rxjs / 7.5.5 / api / operators / mergemapto.html /

mergeMapTo

function deprecated operator

Projects each source value to the same Observable which is merged multiple times in the output Observable.

Deprecation Notes

Will be removed in v9. Use mergeMap instead: mergeMap(() => result)

mergeMapTo<T, R, O extends ObservableInput<unknown>>(innerObservable: O, resultSelector?: number | ((outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R), concurrent: number = Infinity): OperatorFunction<T, ObservedValueOf<O> | R>

Parameters

innerObservable O

An Observable to replace each value from the source Observable.

resultSelector number | ((outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R)

Optional. Default is undefined.

concurrent number

Optional. Default is Infinity.

Maximum number of input Observables being subscribed to concurrently.

Returns

OperatorFunction<T, ObservedValueOf<O> | R>: A function that returns an Observable that emits items from the given innerObservable.

Description

It's like mergeMap, but maps each value always to the same inner Observable.

mergeMapTo marble diagram

Maps each source value to the given Observable innerObservable regardless of the source value, and then merges those resulting Observables into one single Observable, which is the output Observable.

Example

For each click event, start an interval Observable ticking every 1 second

import { fromEvent, mergeMapTo, interval } from 'rxjs';

const clicks = fromEvent(document, 'click');
const result = clicks.pipe(mergeMapTo(interval(1000)));

result.subscribe(x => console.log(x));

See Also

© 2015–2022 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors.
Code licensed under an Apache-2.0 License. Documentation licensed under CC BY 4.0.
https://rxjs.dev/api/operators/mergeMapTo