UNPKG

410 BTypeScriptView Raw
1export default function debounce<T extends (...args: any[]) => void>(
2 func: T,
3 duration: number
4): T {
5 let timeout: NodeJS.Timeout | number | undefined;
6
7 return function (this: any, ...args) {
8 if (!timeout) {
9 // eslint-disable-next-line babel/no-invalid-this
10 func.apply(this, args);
11
12 timeout = setTimeout(() => {
13 timeout = undefined;
14 }, duration);
15 }
16 } as T;
17}