source: trip-planner-front/node_modules/rxjs/src/internal/operators/concatMapTo.ts

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.0 KB
Line 
1import { concatMap } from './concatMap';
2import { ObservableInput, OperatorFunction, ObservedValueOf } from '../types';
3
4/* tslint:disable:max-line-length */
5export function concatMapTo<T, O extends ObservableInput<any>>(observable: O): OperatorFunction<T, ObservedValueOf<O>>;
6/** @deprecated */
7export function concatMapTo<T, O extends ObservableInput<any>>(observable: O, resultSelector: undefined): OperatorFunction<T, ObservedValueOf<O>>;
8/** @deprecated */
9export function concatMapTo<T, R, O extends ObservableInput<any>>(observable: O, resultSelector: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R): 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 a serialized fashion on the output Observable.
15 *
16 * <span class="informal">It's like {@link concatMap}, but maps each value
17 * always to the same inner Observable.</span>
18 *
19 * ![](concatMapTo.png)
20 *
21 * Maps each source value to the given Observable `innerObservable` regardless
22 * of the source value, and then flattens those resulting Observables into one
23 * single Observable, which is the output Observable. Each new `innerObservable`
24 * instance emitted on the output Observable is concatenated with the previous
25 * `innerObservable` instance.
26 *
27 * __Warning:__ if source values arrive endlessly and faster than their
28 * corresponding inner Observables can complete, it will result in memory issues
29 * as inner Observables amass in an unbounded buffer waiting for their turn to
30 * be subscribed to.
31 *
32 * Note: `concatMapTo` is equivalent to `mergeMapTo` with concurrency parameter
33 * set to `1`.
34 *
35 * ## Example
36 * For each click event, tick every second from 0 to 3, with no concurrency
37 * ```ts
38 * import { fromEvent, interval } from 'rxjs';
39 * import { concatMapTo, take } from 'rxjs/operators';
40 *
41 * const clicks = fromEvent(document, 'click');
42 * const result = clicks.pipe(
43 * concatMapTo(interval(1000).pipe(take(4))),
44 * );
45 * result.subscribe(x => console.log(x));
46 *
47 * // Results in the following:
48 * // (results are not concurrent)
49 * // For every click on the "document" it will emit values 0 to 3 spaced
50 * // on a 1000ms interval
51 * // one click = 1000ms-> 0 -1000ms-> 1 -1000ms-> 2 -1000ms-> 3
52 * ```
53 *
54 * @see {@link concat}
55 * @see {@link concatAll}
56 * @see {@link concatMap}
57 * @see {@link mergeMapTo}
58 * @see {@link switchMapTo}
59 *
60 * @param {ObservableInput} innerObservable An Observable to replace each value from
61 * the source Observable.
62 * @return {Observable} An observable of values merged together by joining the
63 * passed observable with itself, one after the other, for each value emitted
64 * from the source.
65 * @method concatMapTo
66 * @owner Observable
67 */
68export function concatMapTo<T, R, O extends ObservableInput<any>>(
69 innerObservable: O,
70 resultSelector?: (outerValue: T, innerValue: ObservedValueOf<O>, outerIndex: number, innerIndex: number) => R
71): OperatorFunction<T, ObservedValueOf<O>|R> {
72 return concatMap(() => innerObservable, resultSelector);
73}
Note: See TracBrowser for help on using the repository browser.