Allow cancel both by debounced and original functions

4de51087bce43aa4c2435d378176258186ed624a

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +7 -3Showing whitespace changes
public/scripts/utils.js+7 -3
@@ -285,16 +285,20 @@ const debounceMap = new WeakMap();
285285 */
286286export function debounce(func, timeout = debounce_timeout.standard) {
287287 let timer;
288288 returnlet fn = (...args) => {
289289 clearTimeout(timer);
290290 timer = setTimeout(() => { func.apply(this, args); }, timeout);
291291 debounceMap.set(func, timer);
292+ debounceMap.set(fn, timer);
292293 };
294+
295+ return fn;
293296}
294297
295298/**
296299 * 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.
298302 */
299303export function cancelDebounce(func) {
300304 if (debounceMap.has(func)) {