UNPKG

1.56 kBTypeScriptView Raw
1import { MonoTypeOperatorFunction, ObservableInput } from '../types';
2/**
3 * Emits the most recently emitted value from the source Observable whenever
4 * another Observable, the `notifier`, emits.
5 *
6 * <span class="informal">It's like {@link sampleTime}, but samples whenever
7 * the `notifier` `ObservableInput` emits something.</span>
8 *
9 * ![](sample.png)
10 *
11 * Whenever the `notifier` `ObservableInput` emits a value, `sample`
12 * looks at the source Observable and emits whichever value it has most recently
13 * emitted since the previous sampling, unless the source has not emitted
14 * anything since the previous sampling. The `notifier` is subscribed to as soon
15 * as the output Observable is subscribed.
16 *
17 * ## Example
18 *
19 * On every click, sample the most recent `seconds` timer
20 *
21 * ```ts
22 * import { fromEvent, interval, sample } from 'rxjs';
23 *
24 * const seconds = interval(1000);
25 * const clicks = fromEvent(document, 'click');
26 * const result = seconds.pipe(sample(clicks));
27 *
28 * result.subscribe(x => console.log(x));
29 * ```
30 *
31 * @see {@link audit}
32 * @see {@link debounce}
33 * @see {@link sampleTime}
34 * @see {@link throttle}
35 *
36 * @param notifier The `ObservableInput` to use for sampling the
37 * source Observable.
38 * @return A function that returns an Observable that emits the results of
39 * sampling the values emitted by the source Observable whenever the notifier
40 * Observable emits value or completes.
41 */
42export declare function sample<T>(notifier: ObservableInput<any>): MonoTypeOperatorFunction<T>;
43//# sourceMappingURL=sample.d.ts.map
\No newline at end of file