* update minor deps * update minor deps * update major deps * fix eslint warnings
14 lines
438 B
TypeScript
14 lines
438 B
TypeScript
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
|
|
export default function debounce<T extends any[]>(
|
|
fn: (...args: T) => unknown,
|
|
wait: number = 1000
|
|
): (...args: Parameters<typeof fn>) => void {
|
|
let timeout: number | undefined;
|
|
return function(this: any, ...args): void {
|
|
const laterCall = (): unknown => fn.apply(this, args);
|
|
window.clearTimeout(timeout);
|
|
timeout = window.setTimeout(laterCall, wait);
|
|
};
|
|
}
|