| 285 | 285 | */ |
| 286 | 286 | export function debounce(func, timeout = debounce_timeout.standard) { |
| 287 | 287 | let timer; |
| 288 | 288 | returnlet fn = (...args) => { |
| 289 | 289 | clearTimeout(timer); |
| 290 | 290 | timer = setTimeout(() => { func.apply(this, args); }, timeout); |
| 291 | 291 | debounceMap.set(func, timer); |
| 292 | + debounceMap.set(fn, timer); |
| 292 | 293 | }; |
| 294 | + |
| 295 | + return fn; |
| 293 | 296 | } |
| 294 | 297 | |
| 295 | 298 | /** |
| 296 | 299 | * Cancels a scheduled debounced function. Does nothing if the function is not debounced or not scheduled. |
| 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 | 303 | export function cancelDebounce(func) { |
| 300 | 304 | if (debounceMap.has(func)) { |