(fn: (...args: Args) => void, delay = 100)
| 1 | export function debounce<Args extends any[]>(fn: (...args: Args) => void, delay = 100) { |
| 2 | if (delay === 0) { |
| 3 | return fn; |
| 4 | } |
| 5 | |
| 6 | let timer: number | undefined; |
| 7 | |
| 8 | return function <U>(this: U, ...args: Args) { |
| 9 | const context = this; |
| 10 | |
| 11 | clearTimeout(timer); |
| 12 | |
| 13 | timer = window.setTimeout(() => { |
| 14 | fn.apply(context, args); |
| 15 | }, delay); |
| 16 | }; |
| 17 | } |
no outgoing calls
no test coverage detected