13 lines
353 B
TypeScript
13 lines
353 B
TypeScript
export function debounce<Params extends any[]>(
|
|
func: (...args: Params) => any,
|
|
delay = 300
|
|
) {
|
|
let debounceTimer: ReturnType<typeof setTimeout>
|
|
|
|
return function <U>(this: U, ...args: Parameters<typeof func>) {
|
|
const context = this
|
|
clearTimeout(debounceTimer)
|
|
debounceTimer = setTimeout(() => func.apply(context, args), delay)
|
|
}
|
|
}
|