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