1.1.0 • Published 6 years ago
@queso/debounce v1.1.0
@queso/debounce
Part of a library of zero-dependency npm modules that do just one thing.
- 100% TypeScript support.
- It's not a party without
Queso!
min + gzip | 199 bytes
Creates a debounced function that delays invoking func until after wait
milliseconds have elapsed since the last time the debounced function was invoked.
Usage
import debounce from '@queso/debounce'
function calculateLayout() {}
const [debounced, cancel] = debounce(calculateLayout, 100)
window.addEventListener('resize', debounced)
cancel()Parameters
| Name | Type | Description |
|---|---|---|
func | TFunc | The function to debounce. |
wait | number | The number of milliseconds to which invocations are debounced. |
{ leading, trailing } | DebounceOptions | Specify invoking on the leading or trailing edge of the timeout (Default is trailing=true). |
Type parameters
| Name | Constraint |
|---|---|
TFunc | (...args: any[]) => any |
Returns
A new debounced function paired with a cancel function.
Return type
[(...args: Parameters<TFunc>) => any, () => void]