UNPKG

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