Learn RxJS
Search…
combineAll

signature: combineAll(project: function): Observable

When source observable completes use combineLatest with collected observables.

Examples

Example 1: Mapping to inner interval observable
1
import { take, map, combineAll } from 'rxjs/operators';
2
import { interval } from 'rxjs';
3
4
// emit every 1s, take 2
5
const source$ = interval(1000).pipe(take(2));
6
// map each emitted value from source to interval observable that takes 5 values
7
const example$ = source$.pipe(
8
map(val =>
9
interval(1000).pipe(
10
map(i => `Result (${val}): ${i}`),
11
take(5)
12
)
13
)
14
);
15
/*
16
2 values from source will map to 2 (inner) interval observables that emit every 1s.
17
combineAll uses combineLatest strategy, emitting the last value from each
18
whenever either observable emits a value
19
*/
20
example$
21
.pipe(combineAll())
22
/*
23
output:
24
["Result (0): 0", "Result (1): 0"]
25
["Result (0): 1", "Result (1): 0"]
26
["Result (0): 1", "Result (1): 1"]
27
["Result (0): 2", "Result (1): 1"]
28
["Result (0): 2", "Result (1): 2"]
29
["Result (0): 3", "Result (1): 2"]
30
["Result (0): 3", "Result (1): 3"]
31
["Result (0): 4", "Result (1): 3"]
32
["Result (0): 4", "Result (1): 4"]
33
*/
34
.subscribe(console.log);
Copied!

Additional Resources

Last modified 1yr ago