RxJS combineLatest is deprecated, so we need to upgrade to combineLatestWith.
Approach
Here’s a simple example. We take observables of the strings hello
and world
and combine them into hello-world
.
const hello$: Observable<string> = of('hello').pipe(
combineLatestWith(of('world')),
map(([hello, world]) => hello + ' - ' + world)
);
hello$.subscribe((v) => console.log(v));
Note that if we have more than 2 streams to combine, combineLatestWith
will nest the arrays, so we need to dereference the nested array structure.
Here's an example.
const helloLoud$: Observable<string> = of('hello').pipe(
combineLatestWith(of('world')),
combineLatestWith(of('!')),
map(([[hello, world], exclamation]) => hello + ' - ' + world + exclamation)
);
helloLoud$.subscribe((v) => console.log(v));