| 285 | */ | 285 | */ |
| 286 | export function debounce(func, timeout = debounce_timeout.standard) { | 286 | export function debounce(func, timeout = debounce_timeout.standard) { |
| 287 | let timer; | 287 | let timer; |
| 288 | return (...args) => { | 288 | let fn = (...args) => { |
| 289 | clearTimeout(timer); | 289 | clearTimeout(timer); |
| 290 | timer = setTimeout(() => { func.apply(this, args); }, timeout); | 290 | timer = setTimeout(() => { func.apply(this, args); }, timeout); |
| 291 | debounceMap.set(func, timer); | 291 | debounceMap.set(func, timer); |
| | 292 | debounceMap.set(fn, timer); |
| 292 | }; | 293 | }; |
| | 294 | |
| | 295 | return fn; |
| 293 | } | 296 | } |
| 294 | | 297 | |
| 295 | /** | 298 | /** |
| 296 | * Cancels a scheduled debounced function. Does nothing if the function is not debounced or not scheduled. | 299 | * Cancels a scheduled debounced function. |
| 297 | * @param {function} func The function to cancel. | 300 | * Does nothing if the function is not debounced or not scheduled. |
| | 301 | * @param {function} func The function to cancel. Either the original or the debounced function. |
| 298 | */ | 302 | */ |
| 299 | export function cancelDebounce(func) { | 303 | export function cancelDebounce(func) { |
| 300 | if (debounceMap.has(func)) { | 304 | if (debounceMap.has(func)) { |