1 import {OperatorFunction, ObservableInput} from '../types';
2 import { switchMap } from './switchMap';
3 import { identity } from '../util/identity';
5 export function switchAll<T>(): OperatorFunction<ObservableInput<T>, T>;
6 export function switchAll<R>(): OperatorFunction<any, R>;
9 * Converts a higher-order Observable into a first-order Observable
10 * producing values only from the most recent observable sequence
12 * <span class="informal">Flattens an Observable-of-Observables.</span>
16 * `switchAll` subscribes to a source that is an observable of observables, also known as a
17 * "higher-order observable" (or `Observable<Observable<T>>`). It subscribes to the most recently
18 * provided "inner observable" emitted by the source, unsubscribing from any previously subscribed
19 * to inner observable, such that only the most recent inner observable may be subscribed to at
20 * any point in time. The resulting observable returned by `switchAll` will only complete if the
21 * source observable completes, *and* any currently subscribed to inner observable also has completed,
25 * Spawn a new interval observable for each click event, but for every new
26 * click, cancel the previous interval and subscribe to the new one.
29 * import { fromEvent, interval } from 'rxjs';
30 * import { switchAll, map, tap } from 'rxjs/operators';
32 * const clicks = fromEvent(document, 'click').pipe(tap(() => console.log('click')));
33 * const source = clicks.pipe(map((ev) => interval(1000)));
37 * ).subscribe(x => console.log(x));
55 * @see {@link combineAll}
56 * @see {@link concatAll}
57 * @see {@link exhaust}
58 * @see {@link switchMap}
59 * @see {@link switchMapTo}
60 * @see {@link mergeAll}
63 export function switchAll<T>(): OperatorFunction<ObservableInput<T>, T> {
64 return switchMap(identity);