| 1 |
import { Observable } from '../Observable'; |
| 2 |
import { ObservableInput, OperatorFunction } from '../types'; |
| 3 |
import { identity } from '../util/identity'; |
| 4 |
import { mapOneOrManyArgs } from '../util/mapOneOrManyArgs'; |
| 5 |
import { pipe } from '../util/pipe'; |
| 6 |
import { mergeMap } from './mergeMap'; |
| 7 |
import { toArray } from './toArray'; |
| 8 |
|
| 9 |
/** |
| 10 |
* Collects all of the inner sources from source observable. Then, once the |
| 11 |
* source completes, joins the values using the given static. |
| 12 |
* |
| 13 |
* This is used for {@link combineLatestAll} and {@link zipAll} which both have the |
| 14 |
* same behavior of collecting all inner observables, then operating on them. |
| 15 |
* |
| 16 |
* @param joinFn The type of static join to apply to the sources collected |
| 17 |
* @param project The projection function to apply to the values, if any |
| 18 |
*/ |
| 19 |
export function joinAllInternals<T, R>(joinFn: (sources: ObservableInput<T>[]) => Observable<T>, project?: (...args: any[]) => R) { |
| 20 |
return pipe( |
| 21 |
// Collect all inner sources into an array, and emit them when the |
| 22 |
// source completes. |
| 23 |
toArray() as OperatorFunction<ObservableInput<T>, ObservableInput<T>[]>, |
| 24 |
// Run the join function on the collected array of inner sources. |
| 25 |
mergeMap((sources) => joinFn(sources)), |
| 26 |
// If a projection function was supplied, apply it to each result. |
| 27 |
project ? mapOneOrManyArgs(project) : (identity as any) |
| 28 |
); |
| 29 |
} |