Files
remark42/frontend/app/utils/debounce.ts
T
2020-08-20 02:53:33 -05:00

14 lines
439 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);
};
}