@tempots/std
debounce() function
Debounce execution of a function. Debouncing, unlike throttling, guarantees that a function is only executed a single time, either at the very beginning of a series of calls, or at the very end.
Signature:
debounce: <FN extends (...args: unknown[]) => void>(delay: number, callback: FN, { atBegin }?: DebounceOptions) => ThrottledFunction<Parameters<FN>>
Parameters
Parameter |
Type |
Description |
---|---|---|
delay |
number |
A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful. |
callback |
FN |
A function to be executed after delay milliseconds. The |
{ atBegin } |
(Optional) |
Returns: ThrottledFunction<Parameters<FN>>
{Function} A new, debounced function.