122d5cfdda100c8c60ac9114e8bbf22c782a25e5e1b9269a7b81a99cea601853c9799975de5416cab1576485ec9dadfabd37f7ff44f6c4e0482db95eae7cce 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { combineLatest } from '../observable/combineLatest';
  2. import { OperatorFunction, ObservableInput } from '../types';
  3. import { joinAllInternals } from './joinAllInternals';
  4. export function combineLatestAll<T>(): OperatorFunction<ObservableInput<T>, T[]>;
  5. export function combineLatestAll<T>(): OperatorFunction<any, T[]>;
  6. export function combineLatestAll<T, R>(project: (...values: T[]) => R): OperatorFunction<ObservableInput<T>, R>;
  7. export function combineLatestAll<R>(project: (...values: Array<any>) => R): OperatorFunction<any, R>;
  8. /**
  9. * Flattens an Observable-of-Observables by applying {@link combineLatest} when the Observable-of-Observables completes.
  10. *
  11. * `combineLatestAll` takes an Observable of Observables, and collects all Observables from it. Once the outer Observable completes,
  12. * it subscribes to all collected Observables and combines their values using the {@link combineLatest} strategy, such that:
  13. *
  14. * * Every time an inner Observable emits, the output Observable emits
  15. * * When the returned observable emits, it emits all of the latest values by:
  16. * * If a `project` function is provided, it is called with each recent value from each inner Observable in whatever order they
  17. * arrived, and the result of the `project` function is what is emitted by the output Observable.
  18. * * If there is no `project` function, an array of all the most recent values is emitted by the output Observable.
  19. *
  20. * ## Example
  21. *
  22. * Map two click events to a finite interval Observable, then apply `combineLatestAll`
  23. *
  24. * ```ts
  25. * import { fromEvent, map, interval, take, combineLatestAll } from 'rxjs';
  26. *
  27. * const clicks = fromEvent(document, 'click');
  28. * const higherOrder = clicks.pipe(
  29. * map(() => interval(Math.random() * 2000).pipe(take(3))),
  30. * take(2)
  31. * );
  32. * const result = higherOrder.pipe(combineLatestAll());
  33. *
  34. * result.subscribe(x => console.log(x));
  35. * ```
  36. *
  37. * @see {@link combineLatest}
  38. * @see {@link combineLatestWith}
  39. * @see {@link mergeAll}
  40. *
  41. * @param project optional function to map the most recent values from each inner Observable into a new result.
  42. * Takes each of the most recent values from each collected inner Observable as arguments, in order.
  43. * @return A function that returns an Observable that flattens Observables
  44. * emitted by the source Observable.
  45. */
  46. export function combineLatestAll<R>(project?: (...values: Array<any>) => R) {
  47. return joinAllInternals(combineLatest, project);
  48. }