apps/rxjs.dev/content/deprecations/scheduler-argument.md
To limit the API surface of some operators, but also prepare for a major refactoring in V8, 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 are not affected by this deprecation.
To support this transition the scheduled creation function 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>If you use any operator from the above list and you're passing the scheduler argument, you have three potential refactoring options.
of and fromscheduled 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 replace this Observable with scheduled and instead of passing the scheduler argument to of pass it to scheduled.
Following code example demonstrate this process.
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));
merge, concat, combineLatest, startWith and endWithIn case you used to pass a scheduler argument to one of these operators you probably had code like this:
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 function.
import { scheduled, of, asyncScheduler, concatAll } from 'rxjs';
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 to refactor the deprecated usage of merge.
With combineLatest, you will want to use combineLatestAll
E.g. code that used to look like this:
import { combineLatest, of, asyncScheduler } from 'rxjs';
combineLatest(of('hello '), of('World'), asyncScheduler).subscribe(console.log);
would become:
import { scheduled, of, asyncScheduler, combineLatestAll } from 'rxjs';
scheduled([of('hello '), of('World')], asyncScheduler)
.pipe(combineLatestAll())
.subscribe((x) => console.log(x));