2 changed files with 13 additions and 0 deletions
@ -0,0 +1,12 @@ |
|||||
|
export function debounce<T extends any[], R = void>(fn: (...argu: T) => R, duration: number = 1500) { |
||||
|
let timer: ReturnType<typeof setTimeout> | void; |
||||
|
return function f(this: void, ...argu: T) { |
||||
|
if (timer) { |
||||
|
clearTimeout(timer); |
||||
|
} |
||||
|
timer = setTimeout(() => { |
||||
|
timer = undefined; |
||||
|
fn.apply(this, argu); |
||||
|
}, duration); |
||||
|
}; |
||||
|
} |
@ -1 +1,2 @@ |
|||||
export * from "./date"; |
export * from "./date"; |
||||
|
export * from "./debounce"; |
||||
|
Loading…
Reference in new issue