combineAll.js 2.2 KB

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