Debian Codegraph @

node/rxjs/src/internal/operators/concatWith.ts

raw
1 import { ObservableInputTuple, OperatorFunction } from '../types';
2 import { concat } from './concat';
3
4 /**
5 * Emits all of the values from the source observable, then, once it completes, subscribes
6 * to each observable source provided, one at a time, emitting all of their values, and not subscribing
7 * to the next one until it completes.
8 *
9 * `concat(a$, b$, c$)` is the same as `a$.pipe(concatWith(b$, c$))`.
10 *
11 * ## Example
12 *
13 * Listen for one mouse click, then listen for all mouse moves.
14 *
15 * ```ts
16 * import { fromEvent, map, take, concatWith } from 'rxjs';
17 *
18 * const clicks$ = fromEvent(document, 'click');
19 * const moves$ = fromEvent(document, 'mousemove');
20 *
21 * clicks$.pipe(
22 * map(() => 'click'),
23 * take(1),
24 * concatWith(
25 * moves$.pipe(
26 * map(() => 'move')
27 * )
28 * )
29 * )
30 * .subscribe(x => console.log(x));
31 *
32 * // 'click'
33 * // 'move'
34 * // 'move'
35 * // 'move'
36 * // ...
37 * ```
38 *
39 * @param otherSources Other observable sources to subscribe to, in sequence, after the original source is complete.
40 * @return A function that returns an Observable that concatenates
41 * subscriptions to the source and provided Observables subscribing to the next
42 * only once the current subscription completes.
43 */
44 export function concatWith<T, A extends readonly unknown[]>(
45 ...otherSources: [...ObservableInputTuple<A>]
46 ): OperatorFunction<T, T | A[number]> {
47 return concat(...otherSources);
48 }