This is just a little warning for all developers using forkJoin
, not a post about how to use it.
If you are looking for a coding example explaining how to use forkJoin
read How To Use ForkJoin - Angular Example (free article).
Deprecation warning
In many examples, you will see syntax like the following.
forkJoin(
of(1, 2),
of(A, B),
)
The code will work but the problem is that the syntax is deprecated and won't work in RxJS v8.
As reported in the documentation, passing Observables directly as parameters is deprecated.
This is called rest-parameter signature and it will be removed in RxJS v8.
RxJS suggests passing an array of sources, as below.
const sources = [of(1, 2), of(A, B)]
forkJoin(sources)
You can find a more realistic example in How To Use ForkJoin - Angular Example (free article), but here is a preview:
sources = [
this.http.get('https://.../users/1'),
this.http.get('https://.../users/2'),
this.http.get('https://.../users/3'),
];
constructor(private http: HttpClient) {}
ngOnInit() {
forkJoin(this.sources).subscribe(console.log);
}
and a link to StackBlitz.
Good To Know
If you work with RxJS and you don't know the RxJS Operator Decision Tree, you should check it out. It will help you find or select the best operator for your needs.
Top comments (6)
On Docs that's still not marked as breaking for V8, but maybe it will be.
And further option is to use a map {name1: source1; name2: source2} as argument.In any case, it will affect
combineLatest
too.Obviously talking about static function.
The homonymous operator will be definitely dropped in favor of
combineLatestWith
.Seems likely to happen. I might write more about RxJS.
Thanks for adding value here!
That's usually what deprecation is.
The state between the breaking change of something being removed and it being in existence.
Yes, but breaking changes for v8 have not been published yet, so saying that "It will not work" is likely but not certain.
The only thing that makes the assertion more valuable is the listing of removing of every long-deprecated API as a step inside roadmap, considering that signature has been deprecated years ago.
That usage is deprecated since 6.5. It might be removed in v8, not just deprecated.
To enable JS syntax highlighting, you can use
(triple backtick) javascript