UNPKG

2.89 kBTypeScriptView Raw
1import { MonoTypeOperatorFunction, ObservableInput } from '../types';
2/**
3 * Emits a notification from the source Observable only after a particular time span
4 * determined by another Observable has passed without another source emission.
5 *
6 * <span class="informal">It's like {@link debounceTime}, but the time span of
7 * emission silence is determined by a second Observable.</span>
8 *
9 * ![](debounce.png)
10 *
11 * `debounce` delays notifications emitted by the source Observable, but drops previous
12 * pending delayed emissions if a new notification arrives on the source Observable.
13 * This operator keeps track of the most recent notification from the source
14 * Observable, and spawns a duration Observable by calling the
15 * `durationSelector` function. The notification is emitted only when the duration
16 * Observable emits a next notification, and if no other notification was emitted on
17 * the source Observable since the duration Observable was spawned. If a new
18 * notification appears before the duration Observable emits, the previous notification will
19 * not be emitted and a new duration is scheduled from `durationSelector` is scheduled.
20 * If the completing event happens during the scheduled duration the last cached notification
21 * is emitted before the completion event is forwarded to the output observable.
22 * If the error event happens during the scheduled duration or after it only the error event is
23 * forwarded to the output observable. The cache notification is not emitted in this case.
24 *
25 * Like {@link debounceTime}, this is a rate-limiting operator, and also a
26 * delay-like operator since output emissions do not necessarily occur at the
27 * same time as they did on the source Observable.
28 *
29 * ## Example
30 * Emit the most recent click after a burst of clicks
31 * ```ts
32 * import { fromEvent, interval } from 'rxjs';
33 * import { scan, debounce } from 'rxjs/operators';
34 *
35 * const clicks = fromEvent(document, 'click');
36 * const result = clicks.pipe(
37 * scan((i) => ++i, 1),
38 * debounce((i) => interval(200 * i))
39 * );
40 * result.subscribe(x => console.log(x));
41 * ```
42 *
43 * @see {@link audit}
44 * @see {@link auditTime}
45 * @see {@link debounce}
46 * @see {@link delay}
47 * @see {@link sample}
48 * @see {@link sampleTime}
49 * @see {@link throttle}
50 * @see {@link throttleTime}
51 *
52 * @param durationSelector A function
53 * that receives a value from the source Observable, for computing the timeout
54 * duration for each source value, returned as an Observable or a Promise.
55 * @return A function that returns an Observable that delays the emissions of
56 * the source Observable by the specified duration Observable returned by
57 * `durationSelector`, and may drop some values if they occur too frequently.
58 */
59export declare function debounce<T>(durationSelector: (value: T) => ObservableInput<any>): MonoTypeOperatorFunction<T>;
60//# sourceMappingURL=debounce.d.ts.map
\No newline at end of file