UNPKG

1.81 kBTypeScriptView Raw
1import { ObservableInputTuple, OperatorFunction, Cons } from '../types';
2/**
3 * Create an observable that combines the latest values from all passed observables and the source
4 * into arrays and emits them.
5 *
6 * Returns an observable, that when subscribed to, will subscribe to the source observable and all
7 * sources provided as arguments. Once all sources emit at least one value, all of the latest values
8 * will be emitted as an array. After that, every time any source emits a value, all of the latest values
9 * will be emitted as an array.
10 *
11 * This is a useful operator for eagerly calculating values based off of changed inputs.
12 *
13 * ### Example
14 *
15 * Simple calculation from two inputs.
16 *
17 * ```ts
18 * import { fromEvent } from 'rxjs';
19 * import { map, combineLatestWith } from 'rxjs/operators';
20 *
21 * // Setup: Add two inputs to the page
22 * const input1 = document.createElement('input');
23 * document.body.appendChild(input1);
24 * const input2 = document.createElement('input');
25 * document.body.appendChild(input2);
26 *
27 * // Get streams of changes
28 * const input1Changes$ = fromEvent(input1, 'change');
29 * const input2Changes$ = fromEvent(input2, 'change');
30 *
31 * // Combine the changes by adding them together
32 * input1Changes$.pipe(
33 * combineLatestWith(input2Changes$),
34 * map(([e1, e2]) => Number(e1.target.value) + Number(e2.target.value)),
35 * )
36 * .subscribe(x => console.log(x));
37 *
38 * ```
39 * @param otherSources the other sources to subscribe to.
40 * @return A function that returns an Observable that emits the latest
41 * emissions from both source and provided Observables.
42 */
43export declare function combineLatestWith<T, A extends readonly unknown[]>(...otherSources: [...ObservableInputTuple<A>]): OperatorFunction<T, Cons<T, A>>;
44//# sourceMappingURL=combineLatestWith.d.ts.map
\No newline at end of file