source: trip-planner-front/node_modules/rxjs/src/internal/operators/combineAll.ts@ e29cc2e

Last change on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.4 KB
Line 
1import { CombineLatestOperator } from '../observable/combineLatest';
2import { Observable } from '../Observable';
3import { OperatorFunction, ObservableInput } from '../types';
4
5export function combineAll<T>(): OperatorFunction<ObservableInput<T>, T[]>;
6export function combineAll<T>(): OperatorFunction<any, T[]>;
7export function combineAll<T, R>(project: (...values: T[]) => R): OperatorFunction<ObservableInput<T>, R>;
8export function combineAll<R>(project: (...values: Array<any>) => R): OperatorFunction<any, R>;
9/**
10 * Flattens an Observable-of-Observables by applying {@link combineLatest} when the Observable-of-Observables completes.
11 *
12 * ![](combineAll.png)
13 *
14 * `combineAll` takes an Observable of Observables, and collects all Observables from it. Once the outer Observable completes,
15 * it subscribes to all collected Observables and combines their values using the {@link combineLatest}</a> strategy, such that:
16 *
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 from each inner Observable in whatever order they
20 * arrived, and the result of the `project` function is what is emitted by the output Observable.
21 * * If there is no `project` function, an array of all the most recent values is emitted by the output Observable.
22 *
23 * ---
24 *
25 * ## Examples
26 *
27 * ### Map two click events to a finite interval Observable, then apply `combineAll`
28 *
29 * ```ts
30 * import { fromEvent, interval } from 'rxjs';
31 * import { map, combineAll, take } from 'rxjs/operators';
32 *
33 * const clicks = fromEvent(document, 'click');
34 * const higherOrder = clicks.pipe(
35 * map(ev =>
36 * interval(Math.random() * 2000).pipe(take(3))
37 * ),
38 * take(2)
39 * );
40 * const result = higherOrder.pipe(
41 * combineAll()
42 * );
43 *
44 * result.subscribe(x => console.log(x));
45 * ```
46 *
47 * @see {@link combineLatest}
48 * @see {@link mergeAll}
49 *
50 * @param {function(...values: Array<any>)} An optional function to map the most recent values from each inner Observable into a new result.
51 * Takes each of the most recent values from each collected inner Observable as arguments, in order.
52 * @return {Observable<T>}
53 * @name combineAll
54 */
55export function combineAll<T, R>(project?: (...values: Array<any>) => R): OperatorFunction<T, R> {
56 return (source: Observable<T>) => source.lift(new CombineLatestOperator(project));
57}
Note: See TracBrowser for help on using the repository browser.