[6a3a178] | 1 | import { Observable } from '../Observable';
|
---|
| 2 | import { OperatorFunction, ObservedValueOf } from '../../internal/types';
|
---|
| 3 | import { mergeMap } from './mergeMap';
|
---|
| 4 | import { ObservableInput } from '../types';
|
---|
| 5 |
|
---|
| 6 | /* tslint:disable:max-line-length */
|
---|
| 7 | export function mergeMapTo<T, O extends ObservableInput<any>>(innerObservable: O, concurrent?: number): OperatorFunction<any, ObservedValueOf<O>>;
|
---|
| 8 | /** @deprecated */
|
---|
| 9 | export function mergeMapTo<T, R, O extends ObservableInput<any>>(innerObservable: O, resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R, concurrent?: number): OperatorFunction<T, R>;
|
---|
| 10 | /* tslint:enable:max-line-length */
|
---|
| 11 |
|
---|
| 12 | /**
|
---|
| 13 | * Projects each source value to the same Observable which is merged multiple
|
---|
| 14 | * times in the output Observable.
|
---|
| 15 | *
|
---|
| 16 | * <span class="informal">It's like {@link mergeMap}, but maps each value always
|
---|
| 17 | * to the same inner Observable.</span>
|
---|
| 18 | *
|
---|
| 19 | * ![](mergeMapTo.png)
|
---|
| 20 | *
|
---|
| 21 | * Maps each source value to the given Observable `innerObservable` regardless
|
---|
| 22 | * of the source value, and then merges those resulting Observables into one
|
---|
| 23 | * single Observable, which is the output Observable.
|
---|
| 24 | *
|
---|
| 25 | * ## Example
|
---|
| 26 | * For each click event, start an interval Observable ticking every 1 second
|
---|
| 27 | * ```ts
|
---|
| 28 | * import { fromEvent, interval } from 'rxjs';
|
---|
| 29 | * import { mergeMapTo } from 'rxjs/operators';
|
---|
| 30 | *
|
---|
| 31 | * const clicks = fromEvent(document, 'click');
|
---|
| 32 | * const result = clicks.pipe(mergeMapTo(interval(1000)));
|
---|
| 33 | * result.subscribe(x => console.log(x));
|
---|
| 34 | * ```
|
---|
| 35 | *
|
---|
| 36 | * @see {@link concatMapTo}
|
---|
| 37 | * @see {@link merge}
|
---|
| 38 | * @see {@link mergeAll}
|
---|
| 39 | * @see {@link mergeMap}
|
---|
| 40 | * @see {@link mergeScan}
|
---|
| 41 | * @see {@link switchMapTo}
|
---|
| 42 | *
|
---|
| 43 | * @param {ObservableInput} innerObservable An Observable to replace each value from
|
---|
| 44 | * the source Observable.
|
---|
| 45 | * @param {number} [concurrent=Number.POSITIVE_INFINITY] Maximum number of input
|
---|
| 46 | * Observables being subscribed to concurrently.
|
---|
| 47 | * @return {Observable} An Observable that emits items from the given
|
---|
| 48 | * `innerObservable`
|
---|
| 49 | * @method mergeMapTo
|
---|
| 50 | * @owner Observable
|
---|
| 51 | */
|
---|
| 52 | export function mergeMapTo<T, R, O extends ObservableInput<any>>(
|
---|
| 53 | innerObservable: O,
|
---|
| 54 | resultSelector?: ((outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R) | number,
|
---|
| 55 | concurrent: number = Number.POSITIVE_INFINITY
|
---|
| 56 | ): OperatorFunction<T, ObservedValueOf<O>|R> {
|
---|
| 57 | if (typeof resultSelector === 'function') {
|
---|
| 58 | return mergeMap(() => innerObservable, resultSelector, concurrent);
|
---|
| 59 | }
|
---|
| 60 | if (typeof resultSelector === 'number') {
|
---|
| 61 | concurrent = resultSelector;
|
---|
| 62 | }
|
---|
| 63 | return mergeMap(() => innerObservable, concurrent);
|
---|
| 64 | }
|
---|