Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecation notes #5821

Merged
merged 7 commits into from
Mar 13, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs(deprecations): add deprecation notes for the resultSelector argu…
…ment
  • Loading branch information
Jan-Niklas Wortmann authored and cartant committed Mar 13, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 022fe516fd1d38731b5cc14a74c59a3d4f60b893
70 changes: 70 additions & 0 deletions docs_app/content/deprecations/resultSelector.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# ResultSelector Parameter

Some operator supported a resultSelector argument that acted as mapping function on the result of that operator.
The same behavior can be reproduced with the `map` operator, therefore this argument became deprecated.

cartant marked this conversation as resolved.
Show resolved Hide resolved
<div class="alert is-important">
<span>
This deprecation was introduced in RxJS 6.0 and will become breaking with RxJS 8.
</span>
</div>

## Operators affected by this Change

- [bindCallback](/api/index/function/bindCallback)
- [bindNodeCallback](/api/index/function/bindNodeCallback)
- [combineLatest](/api/index/function/combineLatest)
- [forkJoin](/api/index/function/forkJoin)
- [fromEvent](/api/index/function/fromEvent)
- [fromEventPattern](/api/index/function/fromEventPattern)
- [zip](/api/index/function/zip)
- [fromEventPattern](/api/index/function/fromEventPattern)
cartant marked this conversation as resolved.
Show resolved Hide resolved
- [concatMap](/api/operators/concatMap)
- [concatMapTo](/api/operators/concatMapTo)
- [exhaustMap](/api/operators/exhaustMap)
- [mergeMap](/api/operators/mergeMap)
- [mergeMapTo](/api/operators/mergeMapTo)
- [switchMap](/api/operators/switchMap)
- [swithMapTo](/api/operators/swithMapTo)

## How to Refactor

Instead of using the `resultSelector` Argument, you can leverage the [`map`](/api/operators/map) operator.
```ts
import {of, combineLatest} from 'rxjs';
import {map} from 'rxjs/operators';

const o1$ = of([1,2,3]);
const o2$ = of([4,5,6]);

// deprecated
combineLatest([o1$, o2$], (o1, o2) => o1+o2)
// suggested change
combineLatest([o1$, o2$]).pipe(
map(([o1, o2]) => o1+o2);
)
```

In case of a higher-order operator, you want to consider using `map` on the inner Observable:

```ts

import {fromEvent, interval} from 'rxjs';
import {switchMap, map} from 'rxjs/operators';

// deprecated
fromEvent(document, 'click').pipe(
switchMap(x => interval(0, 1000), (x) => x+1)
);
// suggested change
fromEvent(document, 'click').pipe(
switchMap(x => interval(0, 1000).pipe(
map(x => x+1)
))
);
```





11 changes: 4 additions & 7 deletions docs_app/content/navigation.json
Original file line number Diff line number Diff line change
@@ -9,13 +9,6 @@
"title": "Reference"
},
{
<<<<<<< HEAD
=======
"url": "guide/v6/migration",
"title": "Migration"
},
{
>>>>>>> docs(deprecations): add index page to describe purpose
"url": "team",
"title": "Team"
}
@@ -87,6 +80,10 @@
{
"url": "deprecations/subscribe-arguments",
"title": "Subscribe Arguments"
},
{
"url": "deprecations/resultSelector",
"title": "ResultSelector Arguments"
}
]
},
2 changes: 1 addition & 1 deletion src/internal/observable/bindNodeCallback.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ import { Observable } from '../Observable';
import { SchedulerLike } from '../types';
import { bindCallbackInternals } from './bindCallbackInternals';

/** @deprecated resultSelector is deprecated, pipe to map instead */
/** @deprecated resultSelector is deprecated, pipe to map instead, Details https://rxjs.dev/deprecations/resultSelector */
export function bindNodeCallback(
callbackFunc: (...args: any[]) => void,
resultSelector: (...args: any[]) => any,
12 changes: 6 additions & 6 deletions src/internal/observable/combineLatest.ts
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ export function combineLatest<A extends readonly unknown[], R>(
resultSelector: (...args: A) => R,
scheduler: SchedulerLike
): Observable<R>;
/** @deprecated resultSelector no longer supported, pipe to map instead */
/** @deprecated resultSelector no longer supported, pipe to map instead, Details https://rxjs.dev/deprecations/resultSelector */
export function combineLatest<A extends readonly unknown[], R>(
sources: readonly [...ObservableInputTuple<A>],
resultSelector: (...args: A) => R
@@ -37,7 +37,7 @@ export function combineLatest<A extends readonly unknown[]>(...sources: [...Obse
export function combineLatest<A extends readonly unknown[], R>(
...args: [...ObservableInputTuple<A>, (...args: A) => R, SchedulerLike]
): Observable<R>;
/** @deprecated resultSelector no longer supported, pipe to map instead */
/** @deprecated resultSelector no longer supported, pipe to map instead, Details https://rxjs.dev/deprecations/resultSelector */
export function combineLatest<A extends readonly unknown[], R>(...args: [...ObservableInputTuple<A>, (...args: A) => R]): Observable<R>;
/** @deprecated The scheduler argument is deprecated, use scheduled and combineLatestAll. Details: https://rxjs.dev/deprecations/scheduler-argument */
export function combineLatest<A extends readonly unknown[]>(...args: [...ObservableInputTuple<A>, SchedulerLike]): Observable<A>;
@@ -48,22 +48,22 @@ export function combineLatest<T extends Record<string, ObservableInput<any>>>(
sourcesObject: T
): Observable<{ [K in keyof T]: ObservedValueOf<T[K]> }>;

/** @deprecated resultSelector no longer supported, pipe to map instead */
/** @deprecated resultSelector no longer supported, pipe to map instead, Details https://rxjs.dev/deprecations/resultSelector */
export function combineLatest<O extends ObservableInput<any>, R>(
array: O[],
resultSelector: (...values: ObservedValueOf<O>[]) => R,
scheduler?: SchedulerLike
): Observable<R>;

/** @deprecated Passing a scheduler here is deprecated, use {@link subscribeOn} and/or {@link observeOn} instead */
/** @deprecated The scheduler argument is deprecated, use scheduled and combineLatestAll. Details: https://rxjs.dev/deprecations/scheduler-argument */
export function combineLatest<O extends ObservableInput<any>>(...observables: Array<O | SchedulerLike>): Observable<any[]>;

/** @deprecated Passing a scheduler here is deprecated, use {@link subscribeOn} and/or {@link observeOn} instead */
/** @deprecated The scheduler argument is deprecated, use scheduled and combineLatestAll. Details: https://rxjs.dev/deprecations/scheduler-argument */
export function combineLatest<O extends ObservableInput<any>, R>(
...observables: Array<O | ((...values: ObservedValueOf<O>[]) => R) | SchedulerLike>
): Observable<R>;

/** @deprecated Passing a scheduler here is deprecated, use {@link subscribeOn} and/or {@link observeOn} instead */
/** @deprecated The scheduler argument is deprecated, use scheduled and combineLatestAll. Details: https://rxjs.dev/deprecations/scheduler-argument */
export function combineLatest<R>(
...observables: Array<ObservableInput<any> | ((...values: Array<any>) => R) | SchedulerLike>
): Observable<R>;
4 changes: 2 additions & 2 deletions src/internal/observable/fromEvent.ts
Original file line number Diff line number Diff line change
@@ -69,10 +69,10 @@ export interface AddEventListenerOptions extends EventListenerOptions {
}

export function fromEvent<T>(target: FromEventTarget<T>, eventName: string): Observable<T>;
/** @deprecated resultSelector no longer supported, pipe to map instead */
/** @deprecated resultSelector no longer supported, pipe to map instead, Details https://rxjs.dev/deprecations/resultSelector */
export function fromEvent<T>(target: FromEventTarget<T>, eventName: string, resultSelector?: (...args: any[]) => T): Observable<T>;
export function fromEvent<T>(target: FromEventTarget<T>, eventName: string, options?: EventListenerOptions): Observable<T>;
/** @deprecated resultSelector no longer supported, pipe to map instead */
/** @deprecated resultSelector no longer supported, pipe to map instead, Details https://rxjs.dev/deprecations/resultSelector */
export function fromEvent<T>(
target: FromEventTarget<T>,
eventName: string,
2 changes: 1 addition & 1 deletion src/internal/observable/fromEventPattern.ts
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ export function fromEventPattern<T>(
addHandler: (handler: NodeEventHandler) => any,
removeHandler?: (handler: NodeEventHandler, signal?: any) => void
): Observable<T>;
/** @deprecated resultSelector no longer supported, pipe to map instead */
/** @deprecated resultSelector no longer supported, pipe to map instead, Details https://rxjs.dev/deprecations/resultSelector */
export function fromEventPattern<T>(
addHandler: (handler: NodeEventHandler) => any,
removeHandler?: (handler: NodeEventHandler, signal?: any) => void,
4 changes: 2 additions & 2 deletions src/internal/observable/zip.ts
Original file line number Diff line number Diff line change
@@ -7,13 +7,13 @@ import { OperatorSubscriber } from '../operators/OperatorSubscriber';
import { popResultSelector } from '../util/args';

export function zip<A extends readonly unknown[]>(sources: [...ObservableInputTuple<A>]): Observable<A>;
/** @deprecated resultSelector is no longer supported, pipe to map instead */
/** @deprecated resultSelector is no longer supported, pipe to map instead, Details https://rxjs.dev/deprecations/resultSelector */
export function zip<A extends readonly unknown[], R>(
sources: [...ObservableInputTuple<A>],
resultSelector: (...values: A) => R
): Observable<R>;
export function zip<A extends readonly unknown[]>(...sources: [...ObservableInputTuple<A>]): Observable<A>;
/** @deprecated resultSelector is no longer supported, pipe to map instead */
/** @deprecated resultSelector is no longer supported, pipe to map instead, Details https://rxjs.dev/deprecations/resultSelector */
export function zip<A extends readonly unknown[], R>(
...sourcesAndResultSelector: [...ObservableInputTuple<A>, (...values: A) => R]
): Observable<R>;
4 changes: 2 additions & 2 deletions src/internal/operators/concatMap.ts
Original file line number Diff line number Diff line change
@@ -6,12 +6,12 @@ import { isFunction } from '../util/isFunction';
export function concatMap<T, O extends ObservableInput<any>>(
project: (value: T, index: number) => O
): OperatorFunction<T, ObservedValueOf<O>>;
/** @deprecated resultSelector no longer supported, use inner map instead */
/** @deprecated resultSelector no longer supported, use inner map instead, Details https://rxjs.dev/deprecations/resultSelector */
export function concatMap<T, O extends ObservableInput<any>>(
project: (value: T, index: number) => O,
resultSelector: undefined
): OperatorFunction<T, ObservedValueOf<O>>;
/** @deprecated resultSelector no longer supported, use inner map instead */
/** @deprecated resultSelector no longer supported, use inner map instead, Details https://rxjs.dev/deprecations/resultSelector */
export function concatMap<T, R, O extends ObservableInput<any>>(
project: (value: T, index: number) => O,
resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R
4 changes: 2 additions & 2 deletions src/internal/operators/concatMapTo.ts
Original file line number Diff line number Diff line change
@@ -4,12 +4,12 @@ import { isFunction } from '../util/isFunction';

/* tslint:disable:max-line-length */
export function concatMapTo<O extends ObservableInput<any>>(observable: O): OperatorFunction<any, ObservedValueOf<O>>;
/** @deprecated */
/** @deprecated resultSelector no longer supported, use inner map instead, Details https://rxjs.dev/deprecations/resultSelector */
export function concatMapTo<O extends ObservableInput<any>>(
observable: O,
resultSelector: undefined
): OperatorFunction<any, ObservedValueOf<O>>;
/** @deprecated */
/** @deprecated resultSelector no longer supported, use inner map instead, Details https://rxjs.dev/deprecations/resultSelector */
export function concatMapTo<T, R, O extends ObservableInput<any>>(
observable: O,
resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R
4 changes: 2 additions & 2 deletions src/internal/operators/exhaustMap.ts
Original file line number Diff line number Diff line change
@@ -10,12 +10,12 @@ import { OperatorSubscriber } from './OperatorSubscriber';
export function exhaustMap<T, O extends ObservableInput<any>>(
project: (value: T, index: number) => O
): OperatorFunction<T, ObservedValueOf<O>>;
/** @deprecated resultSelector is no longer supported. Use inner map instead. */
/** @deprecated resultSelector is no longer supported. Use inner map instead, Details https://rxjs.dev/deprecations/resultSelector */
export function exhaustMap<T, O extends ObservableInput<any>>(
project: (value: T, index: number) => O,
resultSelector: undefined
): OperatorFunction<T, ObservedValueOf<O>>;
/** @deprecated resultSelector is no longer supported. Use inner map instead. */
/** @deprecated resultSelector is no longer supported. Use inner map instead, Details https://rxjs.dev/deprecations/resultSelector */
export function exhaustMap<T, I, R>(
project: (value: T, index: number) => ObservableInput<I>,
resultSelector: (outerValue: T, innerValue: I, outerIndex: number, innerIndex: number) => R
5 changes: 1 addition & 4 deletions src/internal/operators/first.ts
Original file line number Diff line number Diff line change
@@ -34,10 +34,7 @@ export function first<T, D = T>(
*
* If called with no arguments, `first` emits the first value of the source
* Observable, then completes. If called with a `predicate` function, `first`
* emits the first value of the source that matches the specified condition. It
* may also take a deprecated `resultSelector` function to produce the output
* value from the input value, and a `defaultValue` to emit in case the source
* completes before it is able to emit a valid value. Throws an error if
* emits the first value of the source that matches the specified condition. Throws an error if
* `defaultValue` was not provided and a matching element is not found.
*
* ## Examples
4 changes: 2 additions & 2 deletions src/internal/operators/mergeMap.ts
Original file line number Diff line number Diff line change
@@ -10,13 +10,13 @@ export function mergeMap<T, O extends ObservableInput<any>>(
project: (value: T, index: number) => O,
concurrent?: number
): OperatorFunction<T, ObservedValueOf<O>>;
/** @deprecated resultSelector no longer supported, use inner map instead */
/** @deprecated resultSelector no longer supported, use inner map instead, Details https://rxjs.dev/deprecations/resultSelector */
export function mergeMap<T, O extends ObservableInput<any>>(
project: (value: T, index: number) => O,
resultSelector: undefined,
concurrent?: number
): OperatorFunction<T, ObservedValueOf<O>>;
/** @deprecated resultSelector no longer supported, use inner map instead */
/** @deprecated resultSelector no longer supported, use inner map instead, Details https://rxjs.dev/deprecations/resultSelector */
export function mergeMap<T, R, O extends ObservableInput<any>>(
project: (value: T, index: number) => O,
resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R,
4 changes: 2 additions & 2 deletions src/internal/operators/switchMap.ts
Original file line number Diff line number Diff line change
@@ -8,12 +8,12 @@ import { OperatorSubscriber } from './OperatorSubscriber';
export function switchMap<T, O extends ObservableInput<any>>(
project: (value: T, index: number) => O
): OperatorFunction<T, ObservedValueOf<O>>;
/** @deprecated resultSelector is no longer supported, use inner map instead */
/** @deprecated resultSelector is no longer supported, use inner map instead, Details https://rxjs.dev/deprecations/resultSelector */
export function switchMap<T, O extends ObservableInput<any>>(
project: (value: T, index: number) => O,
resultSelector: undefined
): OperatorFunction<T, ObservedValueOf<O>>;
/** @deprecated resultSelector is no longer supported, use inner map instead */
/** @deprecated resultSelector is no longer supported, use inner map instead, Details https://rxjs.dev/deprecations/resultSelector */
export function switchMap<T, R, O extends ObservableInput<any>>(
project: (value: T, index: number) => O,
resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R
4 changes: 2 additions & 2 deletions src/internal/operators/switchMapTo.ts
Original file line number Diff line number Diff line change
@@ -3,9 +3,9 @@ import { switchMap } from './switchMap';

/* tslint:disable:max-line-length */
export function switchMapTo<R>(observable: ObservableInput<R>): OperatorFunction<any, R>;
/** @deprecated resultSelector is no longer supported. Switch to using switchMap with an inner map */
/** @deprecated resultSelector is no longer supported. Switch to using switchMap with an inner map, Details https://rxjs.dev/deprecations/resultSelector */
export function switchMapTo<R>(observable: ObservableInput<R>, resultSelector: undefined): OperatorFunction<any, R>;
/** @deprecated resultSelector is no longer supported. Switch to using switchMap with an inner map */
/** @deprecated resultSelector is no longer supported. Switch to using switchMap with an inner map, Details https://rxjs.dev/deprecations/resultSelector */
export function switchMapTo<T, I, R>(observable: ObservableInput<I>, resultSelector: (outerValue: T, innerValue: I, outerIndex: number, innerIndex: number) => R): OperatorFunction<T, R>;
/* tslint:enable:max-line-length */