-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs]: Create Deprecation page per deprecation group (#5426)
* docs(deprecation): init deprecation section * docs(deprecations): add scheduler deprecation page and adjust deprecation messages * docs(deprecations): remove jsdoc style from deprecation message * chore: fix typos * chore: make changes to address my comments Co-authored-by: Jan-Niklas Wortmann <[email protected]> Co-authored-by: Nicholas Jamieson <[email protected]>
- Loading branch information
1 parent
2d5e4d5
commit d52c766
Showing
11 changed files
with
190 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# Scheduler Argument | ||
|
||
To limit the API surface of some operators, but also prepare for a [major refactoring in V8](https://github.com/ReactiveX/rxjs/pull/4583), we | ||
agreed on deprecating the `scheduler` argument from many operators. It solely deprecates those methods where this argument is rarely used. So `time` related | ||
operators, like [`interval`](https://rxjs.dev/api/index/function/interval) are not affected by this deprecation. | ||
|
||
To support this transition the [scheduled creation function](/api/index/function/scheduled) was added. | ||
|
||
<div class="alert is-important"> | ||
<span> | ||
This deprecation was introduced in **RxJS 6.5** and will become breaking with **RxJS 8**. | ||
</span> | ||
</div> | ||
|
||
## Operators affected by this Change | ||
|
||
- [from](/api/index/function/from) | ||
- [of](/api/index/function/of) | ||
- [merge](/api/index/function/merge) | ||
- [concat](/api/index/function/concat) | ||
- [startWith](/api/operators/startWith) | ||
- [endWith](/api/operators/endWith) | ||
- [combineLatest](/api/index/function/combineLatest) | ||
|
||
## How to Refactor | ||
|
||
If you use any other operator from the list above and using the `scheduler` argument, you have to three potential refactoring options. | ||
|
||
### Refactoring of `of` and `from` | ||
|
||
`scheduled` is kinda copying the behavior of `from`. Therefore if you used `from` with a `scheduler` argument, you can just replace them. | ||
|
||
For the `of` creation function you need to this Observable with `scheduled` and instead of passing the `scheduler` argument to `of` pass it to `scheduled`. | ||
Following code example demonstrate this process. | ||
|
||
```ts | ||
import { of, asyncScheduler, scheduled } from 'rxjs'; | ||
|
||
// Deprecated approach | ||
of([1,2,3], asyncScheduler).subscribe(x => console.log(x)); | ||
// suggested approach | ||
scheduled([1,2,3], asyncScheduler).subscribe(x => console.log(x)); | ||
``` | ||
|
||
### Refactoring of `merge`, `concat`, `combineLatest`, `startWith` and `endWith` | ||
|
||
In case you used to pass a scheduler argument to one of these operators you probably had code like this: | ||
|
||
```ts | ||
import { concat, of, asyncScheduler } from 'rxjs'; | ||
|
||
concat( | ||
of('hello '), | ||
of('World'), | ||
asyncScheduler | ||
).subscribe(x => console.log(x)); | ||
``` | ||
|
||
To work around this deprecation you can leverage the [`scheduled`](/api/index/function/scheduled) function. | ||
|
||
```ts | ||
import { scheduled, of, asyncScheduler } from 'rxjs'; | ||
import { concatAll } from 'rxjs/operators' | ||
|
||
scheduled( | ||
[of('hello '), of('World')], | ||
asyncScheduler | ||
).pipe( | ||
concatAll() | ||
).subscribe(x => console.log(x)); | ||
``` | ||
|
||
You can apply this pattern to refactor deprecated usage of `concat`, `startWith` and `endWith` but do notice that you will want to use [mergeAll](/api/operators/mergeAll) to refactor the deprecated usage of `merge`. | ||
|
||
With `combineLatest`, you will want to use [combineAll](/api/operators/combineAll) | ||
|
||
E.g. code that used to look like this: | ||
|
||
```ts | ||
import { combineLatest, of, asyncScheduler } from 'rxjs'; | ||
|
||
combineLatest( | ||
of('hello '), | ||
of('World'), | ||
asyncScheduler | ||
).subscribe(console.log) | ||
``` | ||
|
||
would become: | ||
|
||
```ts | ||
import { scheduled, of, asyncScheduler } from 'rxjs'; | ||
import { combineAll } from 'rxjs/operators' | ||
|
||
scheduled( | ||
[of('hello '), of('World')], | ||
asyncScheduler | ||
).pipe( | ||
combineAll() | ||
).subscribe(x => console.log(x)); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Higher-order Observables | ||
|
||
Observables most commonly emit ordinary values like strings and numbers, but surprisingly often, it is necessary to handle Observables *of* Observables, so-called higher-order Observables. For example, imagine you have an Observable emitting strings that are the URLs of files you want to fetch. The code might look like this: | ||
|
||
```ts | ||
const fileObservable = urlObservable.pipe( | ||
map(url => http.get(url)), | ||
); | ||
``` | ||
|
||
`http.get()` returns an Observable for each URL. Now you have an Observable *of* Observables, a higher-order Observable. | ||
|
||
But how do you work with a higher-order Observable? Typically, by _flattening_: by converting a higher-order Observable into an ordinary Observable. For example: | ||
|
||
```ts | ||
const fileObservable = urlObservable.pipe( | ||
concatMap(url => http.get(url)), | ||
); | ||
``` | ||
|
||
The Observable returned in the `concatMap` function is usually referred to as a so-called "inner" Observable, while in this context the `urlObservable` is the so-called "outer" Observable. | ||
|
||
The [`concatMap()`](/api/operators/concatMap) operator subscribes to each "inner" Observable, buffers all further emissions of the "outer" Observable, and copies all the emitted values until the inner Observable completes, and continues processing the values of the "outer Observable". All of the values are in that way concatenated. Other useful flattening operators are | ||
|
||
* [`mergeMap()`](/api/operators/mergeMap) — subscribes to each inner Observable as it arrives, then emits each value as it arrives | ||
* [`switchMap()`](/api/operators/switchMap) — subscribes to the first inner Observable when it arrives, and emits each value as it arrives, but when the next inner Observable arrives, unsubscribes to the previous one, and subscribes to the new one. | ||
* [`exhaustMap()`](/api/operators/exhaustMap) — subscribes to the first inner Observable when it arrives, and emits each value as it arrives, discarding all newly arriving inner Observables until that first one completes, then waits for the next inner Observable. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.