(this: T, ...args: A)
| 14 | let currentFunc = func |
| 15 | |
| 16 | const debounced = function debounced(this: T, ...args: A): void { |
| 17 | const later = () => { |
| 18 | timeout = null |
| 19 | if (!immediate) { |
| 20 | currentFunc.apply(this, args) |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | if (immediate && !timeout) { |
| 25 | /** |
| 26 | * there's no need to clear the timeout |
| 27 | * since we expect it to resolve and set `timeout = null` |
| 28 | */ |
| 29 | currentFunc.apply(this, args) |
| 30 | timeout = setTimeout(later, wait) |
| 31 | } |
| 32 | |
| 33 | if (!immediate) { |
| 34 | if (timeout) { |
| 35 | clearTimeout(timeout) |
| 36 | } |
| 37 | timeout = setTimeout(later, wait) |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | debounced.cancel = () => { |
| 42 | /* c8 ignore start */ |
nothing calls this directly
no outgoing calls
no test coverage detected