UNPKG

1.78 kBTypeScriptView Raw
1import { LodashMethodDecorator } from './factory';
2import { DebounceOptions } from './shared';
3declare const decorator: (...args: any[]) => MethodDecorator & PropertyDecorator;
4/**
5 * Creates a debounced function that delays invoking func until after wait milliseconds have elapsed since the last time the debounced function was invoked.
6 * The debounced function comes with a cancel method to cancel delayed func invocations and a flush method to immediately invoke them.
7 * Provide options to indicate whether func should be invoked on the leading and/or trailing edge of the wait timeout. The func is invoked with the last arguments provided to the debounced function.
8 * Subsequent calls to the debounced function return the result of the last func invocation.
9 *
10 * The debounce state is shared across all instances of the class.
11 *
12 * Note: If leading and trailing options are true, func is invoked on the trailing edge of the timeout only if the debounced function is invoked more than once during the wait timeout.
13 *
14 * If wait is 0 and leading is false, func invocation is deferred until to the next tick, similar to setTimeout with a timeout of 0.
15 *
16 * @param {number} [wait=0] The number in milliseconds to delay.
17 * @param {DebounceOptions} [options] The options object.
18 * @example
19 *
20 * class MyClass {
21 * value = 100;
22 *
23 * @DebounceAll(10)
24 * add(a) {
25 * this.value += a;
26 * }
27 * }
28 *
29 * const myClass = new MyClass();
30 *
31 * myClass.add(10);
32 * myClass.add(50);
33 * myClass.add(20);
34 *
35 * myClass.value; // => 100;
36 *
37 * setTimeout(() => {
38 * myClass.value; // => 120;
39 * }, 11);
40 */
41export declare function DebounceAll(wait?: number, options?: DebounceOptions): LodashMethodDecorator;
42export { DebounceAll as debounceAll };
43export default decorator;