1 | type AnyFunction = (...arguments_: readonly any[]) => unknown;
|
2 |
|
3 | /**
|
4 | Creates a debounced function that delays execution until `wait` milliseconds have passed since its last invocation.
|
5 |
|
6 | Set the `immediate` option to `true` to execute the function immediately at the start of the `wait` interval, preventing issues such as double-clicks on a button.
|
7 |
|
8 | The returned function has the following methods:
|
9 |
|
10 | - `.isPending` indicates whether the debounce delay is currently active.
|
11 | - `.clear()` cancels any scheduled executions.
|
12 | - `.flush()` if an execution is scheduled then it will be immediately executed and the timer will be cleared.
|
13 | - `.trigger()` executes the function immediately and clears the timer if it was previously set.
|
14 | */
|
15 | declare function debounce<F extends AnyFunction>(
|
16 | function_: F,
|
17 | wait?: number,
|
18 | options?: {immediate: boolean}
|
19 | ): debounce.DebouncedFunction<F>;
|
20 |
|
21 | declare namespace debounce {
|
22 | type DebouncedFunction<F extends AnyFunction> = {
|
23 | (...arguments_: Parameters<F>): ReturnType<F> | undefined;
|
24 | readonly isPending: boolean;
|
25 | clear(): void;
|
26 | flush(): void;
|
27 | trigger(): void;
|
28 | };
|
29 | }
|
30 |
|
31 | export = debounce;
|