Function
debounce
(fn: (...args: TArgs) => void, delay: number)
Source from the content-addressed store, hash-verified
| 48 | * Debounces calling `fn` for `delay` ms |
| 49 | */ |
| 50 | export function debounce<TArgs extends Array<any>>(fn: (...args: TArgs) => void, delay: number) { |
| 51 | let timeout; |
| 52 | return function(...args: TArgs) { |
| 53 | if (delay) { |
| 54 | clearTimeout(timeout); |
| 55 | timeout = setTimeout(fn, delay, args); |
| 56 | } else { |
| 57 | fn.apply(this, args); |
| 58 | } |
| 59 | return delay; |
| 60 | }; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Converts 'start' to 'left', 'end' to 'right' and others to 'center' |
Tested by
no test coverage detected