(fn: Function, delay = 300)
| 27 | * @returns A new throttled function |
| 28 | */ |
| 29 | export function throttle(fn: Function, delay = 300) { |
| 30 | let waiting = false; |
| 31 | return function (...args) { |
| 32 | if (!waiting) { |
| 33 | fn.apply(this, args); |
| 34 | waiting = true; |
| 35 | setTimeout(function () { |
| 36 | waiting = false; |
| 37 | }, delay); |
| 38 | } |
| 39 | }; |
| 40 | } |
no test coverage detected