combineAll

signature: combineAll(project: function): Observable

When source observable completes use combineLatest with collected observables.

combineAll - 图1

Examples

(
example tests
)

Example 1: Mapping to inner interval observable

( StackBlitz |
jsBin |
jsFiddle )

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

Additional Resources


:file_folder: Source Code:
https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/combineAll.ts