Contents

combineAll operator in RxJs

Updated on 2021-02-09

combineAll Operator

Can be imported from here:

1
2
3
import { combineAll } from 'rxjs/operators';
// or
const { combineAll } = require('rxjs/operators');

For official documentation, visit https://rxjs.dev/api/operators/combineAll

Flattens an Observable of Observables by applying combineLatest when the Observable of Observables complete.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
import { take, map, combineAll } from 'rxjs/operators';
import { interval, from } from 'rxjs';

const array1 = ['a', 'b', 'c', 'd', 'e'];
const array2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];


const ob1$ = interval(2000).pipe(take(array1.length), map((i) => array1[i]));
const ob2$ = interval(1000).pipe(take(array2.length), map((i) => array2[i]));

const observableOfObservables$ = from([ob1$, ob2$]);

const result$ = observableOfObservables$.pipe(combineAll());

result$.subscribe((val) => console.log(`(${val[0]}, ${val[1]})`));
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
(a, 1)
(a, 2)
(a, 3)
(b, 3)
(b, 4)
(b, 5)
(c, 5)
(c, 6)
(c, 7)
(d, 7)
(d, 8)
(d, 9)
(e, 9)
(e, 10)
/rxjs/combineAll.svg
combineAll() Example

Комментарии