84424744d4e6946a9628ae1f9aca87f82354eae4
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / rxjs / src / internal / operators / switchMapTo.ts
1 import { Operator } from '../Operator';
2 import { Observable } from '../Observable';
3 import { Subscriber } from '../Subscriber';
4 import { Subscription } from '../Subscription';
5 import { OuterSubscriber } from '../OuterSubscriber';
6 import { InnerSubscriber } from '../InnerSubscriber';
7 import { subscribeToResult } from '../util/subscribeToResult';
8 import { ObservableInput, OperatorFunction } from '../types';
9 import { switchMap } from './switchMap';
10
11 /* tslint:disable:max-line-length */
12 export function switchMapTo<R>(observable: ObservableInput<R>): OperatorFunction<any, R>;
13 /** @deprecated resultSelector is no longer supported. Switch to using switchMap with an inner map */
14 export function switchMapTo<T, R>(observable: ObservableInput<R>, resultSelector: undefined): OperatorFunction<T, R>;
15 /** @deprecated resultSelector is no longer supported. Switch to using switchMap with an inner map */
16 export function switchMapTo<T, I, R>(observable: ObservableInput<I>, resultSelector: (outerValue: T, innerValue: I, outerIndex: number, innerIndex: number) => R): OperatorFunction<T, R>;
17 /* tslint:enable:max-line-length */
18
19 /**
20  * Projects each source value to the same Observable which is flattened multiple
21  * times with {@link switchMap} in the output Observable.
22  *
23  * <span class="informal">It's like {@link switchMap}, but maps each value
24  * always to the same inner Observable.</span>
25  *
26  * ![](switchMapTo.png)
27  *
28  * Maps each source value to the given Observable `innerObservable` regardless
29  * of the source value, and then flattens those resulting Observables into one
30  * single Observable, which is the output Observable. The output Observables
31  * emits values only from the most recently emitted instance of
32  * `innerObservable`.
33  *
34  * ## Example
35  * Rerun an interval Observable on every click event
36  * ```ts
37  * import { fromEvent, interval } from 'rxjs';
38  * import { switchMapTo } from 'rxjs/operators';
39  *
40  * const clicks = fromEvent(document, 'click');
41  * const result = clicks.pipe(switchMapTo(interval(1000)));
42  * result.subscribe(x => console.log(x));
43  * ```
44  *
45  * @see {@link concatMapTo}
46  * @see {@link switchAll}
47  * @see {@link switchMap}
48  * @see {@link mergeMapTo}
49  *
50  * @param {ObservableInput} innerObservable An Observable to replace each value from
51  * the source Observable.
52  * @return {Observable} An Observable that emits items from the given
53  * `innerObservable` (and optionally transformed through the deprecated `resultSelector`)
54  * every time a value is emitted on the source Observable, and taking only the values
55  * from the most recently projected inner Observable.
56  * @method switchMapTo
57  * @owner Observable
58  */
59 export function switchMapTo<T, I, R>(
60   innerObservable: ObservableInput<I>,
61   resultSelector?: (outerValue: T, innerValue: I, outerIndex: number, innerIndex: number) => R
62 ): OperatorFunction<T, I|R> {
63   return resultSelector ? switchMap(() => innerObservable, resultSelector) : switchMap(() => innerObservable);
64 }