combineAll.d.ts 2.0KB

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