UNPKG

3.22 kBTypeScriptView Raw
1import { MonoTypeOperatorFunction, ObservableInput } from '../types';
2/**
3 * An object interface used by {@link throttle} or {@link throttleTime} that ensure
4 * configuration options of these operators.
5 *
6 * @see {@link throttle}
7 * @see {@link throttleTime}
8 */
9export interface ThrottleConfig {
10 /**
11 * If `true`, the resulting Observable will emit the first value from the source
12 * Observable at the **start** of the "throttling" process (when starting an
13 * internal timer that prevents other emissions from the source to pass through).
14 * If `false`, it will not emit the first value from the source Observable at the
15 * start of the "throttling" process.
16 *
17 * If not provided, defaults to: `true`.
18 */
19 leading?: boolean;
20 /**
21 * If `true`, the resulting Observable will emit the last value from the source
22 * Observable at the **end** of the "throttling" process (when ending an internal
23 * timer that prevents other emissions from the source to pass through).
24 * If `false`, it will not emit the last value from the source Observable at the
25 * end of the "throttling" process.
26 *
27 * If not provided, defaults to: `false`.
28 */
29 trailing?: boolean;
30}
31/**
32 * Emits a value from the source Observable, then ignores subsequent source
33 * values for a duration determined by another Observable, then repeats this
34 * process.
35 *
36 * <span class="informal">It's like {@link throttleTime}, but the silencing
37 * duration is determined by a second Observable.</span>
38 *
39 * ![](throttle.svg)
40 *
41 * `throttle` emits the source Observable values on the output Observable
42 * when its internal timer is disabled, and ignores source values when the timer
43 * is enabled. Initially, the timer is disabled. As soon as the first source
44 * value arrives, it is forwarded to the output Observable, and then the timer
45 * is enabled by calling the `durationSelector` function with the source value,
46 * which returns the "duration" Observable. When the duration Observable emits a
47 * value, the timer is disabled, and this process repeats for the
48 * next source value.
49 *
50 * ## Example
51 *
52 * Emit clicks at a rate of at most one click per second
53 *
54 * ```ts
55 * import { fromEvent, throttle, interval } from 'rxjs';
56 *
57 * const clicks = fromEvent(document, 'click');
58 * const result = clicks.pipe(throttle(() => interval(1000)));
59 *
60 * result.subscribe(x => console.log(x));
61 * ```
62 *
63 * @see {@link audit}
64 * @see {@link debounce}
65 * @see {@link delayWhen}
66 * @see {@link sample}
67 * @see {@link throttleTime}
68 *
69 * @param durationSelector A function that receives a value from the source
70 * Observable, for computing the silencing duration for each source value,
71 * returned as an `ObservableInput`.
72 * @param config A configuration object to define `leading` and `trailing`
73 * behavior. Defaults to `{ leading: true, trailing: false }`.
74 * @return A function that returns an Observable that performs the throttle
75 * operation to limit the rate of emissions from the source.
76 */
77export declare function throttle<T>(durationSelector: (value: T) => ObservableInput<any>, config?: ThrottleConfig): MonoTypeOperatorFunction<T>;
78//# sourceMappingURL=throttle.d.ts.map
\No newline at end of file