-
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(deprecations): add scheduler deprecation page and adjust depreca…
…tion messages
- Loading branch information
1 parent
60d1d35
commit 19618d1
Showing
10 changed files
with
154 additions
and
54 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 barely 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) | ||
- [combineLates](/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(of([1,2,3]), asyncScheduler).subscribe(x => console.log(x)); | ||
``` | ||
|
||
### Refactoring of `merge`, `concat`, `startWith` and `endWith` | ||
|
||
In case you used to pass a scheduler argument to one of these operators you propably 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 want to use [mergeAll](/api/operators/mergeAll) to refactor the deprecated usage of `merge`. | ||
|
||
### Refactoring `combineLatest` | ||
|
||
Unfortunately, there's no point in using `scheduled` with `combineLatest`. You rather want to leverage [`subscribeOn`](/api/operators/subscribeOn) or [`observeOn`](/api/operators/observeOn) depending on your goals. | ||
|
||
E.g. code that used to look like this: | ||
|
||
```ts | ||
import { combineLatest, timer, asyncScheduler } from 'rxjs'; | ||
|
||
combineLatest( | ||
[timer(0, 1000), timer(500, 500)], | ||
asyncScheduler | ||
).subscribe(console.log) | ||
``` | ||
|
||
would become: | ||
|
||
```ts | ||
import { combineLatest, timer, asyncScheduler } from 'rxjs'; | ||
import { subscribeOn } from 'rxjs/operators' | ||
|
||
combineLatest( | ||
[timer(0, 1000), timer(500, 500)], | ||
).pipe( | ||
subscribeOn(asyncScheduler) | ||
).subscribe(console.log) | ||
``` |
This file was deleted.
Oops, something went wrong.
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.