combineAll.js 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /** PURE_IMPORTS_START .._operators_combineAll PURE_IMPORTS_END */
  2. import { combineAll as higherOrder } from '../operators/combineAll';
  3. /**
  4. * Converts a higher-order Observable into a first-order Observable by waiting
  5. * for the outer Observable to complete, then applying {@link combineLatest}.
  6. *
  7. * <span class="informal">Flattens an Observable-of-Observables by applying
  8. * {@link combineLatest} when the Observable-of-Observables completes.</span>
  9. *
  10. * <img src="./img/combineAll.png" width="100%">
  11. *
  12. * Takes an Observable of Observables, and collects all Observables from it.
  13. * Once the outer Observable completes, it subscribes to all collected
  14. * Observables and combines their values using the {@link combineLatest}
  15. * strategy, such that:
  16. * - Every time an inner Observable emits, the output Observable emits.
  17. * - When the returned observable emits, it emits all of the latest values by:
  18. * - If a `project` function is provided, it is called with each recent value
  19. * from each inner Observable in whatever order they arrived, and the result
  20. * of the `project` function is what is emitted by the output Observable.
  21. * - If there is no `project` function, an array of all of the most recent
  22. * values is emitted by the output Observable.
  23. *
  24. * @example <caption>Map two click events to a finite interval Observable, then apply combineAll</caption>
  25. * var clicks = Rx.Observable.fromEvent(document, 'click');
  26. * var higherOrder = clicks.map(ev =>
  27. * Rx.Observable.interval(Math.random()*2000).take(3)
  28. * ).take(2);
  29. * var result = higherOrder.combineAll();
  30. * result.subscribe(x => console.log(x));
  31. *
  32. * @see {@link combineLatest}
  33. * @see {@link mergeAll}
  34. *
  35. * @param {function} [project] An optional function to map the most recent
  36. * values from each inner Observable into a new result. Takes each of the most
  37. * recent values from each collected inner Observable as arguments, in order.
  38. * @return {Observable} An Observable of projected results or arrays of recent
  39. * values.
  40. * @method combineAll
  41. * @owner Observable
  42. */
  43. export function combineAll(project) {
  44. return higherOrder(project)(this);
  45. }
  46. //# sourceMappingURL=combineAll.js.map