Debian Codegraph @

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

raw
1 import { ObservableInputTuple, OperatorFunction } from '../types';
2 import { merge } from './merge';
3
4 /**
5 * Merge the values from all observables to a single observable result.
6 *
7 * Creates an observable, that when subscribed to, subscribes to the source
8 * observable, and all other sources provided as arguments. All values from
9 * every source are emitted from the resulting subscription.
10 *
11 * When all sources complete, the resulting observable will complete.
12 *
13 * When any source errors, the resulting observable will error.
14 *
15 * ## Example
16 *
17 * Joining all outputs from multiple user input event streams
18 *
19 * ```ts
20 * import { fromEvent, map, mergeWith } from 'rxjs';
21 *
22 * const clicks$ = fromEvent(document, 'click').pipe(map(() => 'click'));
23 * const mousemoves$ = fromEvent(document, 'mousemove').pipe(map(() => 'mousemove'));
24 * const dblclicks$ = fromEvent(document, 'dblclick').pipe(map(() => 'dblclick'));
25 *
26 * mousemoves$
27 * .pipe(mergeWith(clicks$, dblclicks$))
28 * .subscribe(x => console.log(x));
29 *
30 * // result (assuming user interactions)
31 * // 'mousemove'
32 * // 'mousemove'
33 * // 'mousemove'
34 * // 'click'
35 * // 'click'
36 * // 'dblclick'
37 * ```
38 *
39 * @see {@link merge}
40 *
41 * @param otherSources the sources to combine the current source with.
42 * @return A function that returns an Observable that merges the values from
43 * all given Observables.
44 */
45 export function mergeWith<T, A extends readonly unknown[]>(
46 ...otherSources: [...ObservableInputTuple<A>]
47 ): OperatorFunction<T, T | A[number]> {
48 return merge(...otherSources);
49 }