UNPKG

2.05 kBTypeScriptView Raw
1import { OperatorFunction, ObservableInput, ObservedValueOf } from '../types';
2/**
3 * Converts a higher-order Observable into a first-order Observable
4 * producing values only from the most recent observable sequence
5 *
6 * <span class="informal">Flattens an Observable-of-Observables.</span>
7 *
8 * ![](switchAll.png)
9 *
10 * `switchAll` subscribes to a source that is an observable of observables, also known as a
11 * "higher-order observable" (or `Observable<Observable<T>>`). It subscribes to the most recently
12 * provided "inner observable" emitted by the source, unsubscribing from any previously subscribed
13 * to inner observable, such that only the most recent inner observable may be subscribed to at
14 * any point in time. The resulting observable returned by `switchAll` will only complete if the
15 * source observable completes, *and* any currently subscribed to inner observable also has completed,
16 * if there are any.
17 *
18 * ## Examples
19 *
20 * Spawn a new interval observable for each click event, but for every new
21 * click, cancel the previous interval and subscribe to the new one
22 *
23 * ```ts
24 * import { fromEvent, tap, map, interval, switchAll } from 'rxjs';
25 *
26 * const clicks = fromEvent(document, 'click').pipe(tap(() => console.log('click')));
27 * const source = clicks.pipe(map(() => interval(1000)));
28 *
29 * source
30 * .pipe(switchAll())
31 * .subscribe(x => console.log(x));
32 *
33 * // Output
34 * // click
35 * // 0
36 * // 1
37 * // 2
38 * // 3
39 * // ...
40 * // click
41 * // 0
42 * // 1
43 * // 2
44 * // ...
45 * // click
46 * // ...
47 * ```
48 *
49 * @see {@link combineLatestAll}
50 * @see {@link concatAll}
51 * @see {@link exhaustAll}
52 * @see {@link switchMap}
53 * @see {@link switchMapTo}
54 * @see {@link mergeAll}
55 *
56 * @return A function that returns an Observable that converts a higher-order
57 * Observable into a first-order Observable producing values only from the most
58 * recent Observable sequence.
59 */
60export declare function switchAll<O extends ObservableInput<any>>(): OperatorFunction<O, ObservedValueOf<O>>;
61//# sourceMappingURL=switchAll.d.ts.map
\No newline at end of file