mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2024-12-12 09:26:33 +01:00
Allow cancel both by debounced and original functions
This commit is contained in:
parent
17dc3fa4b5
commit
4de51087bc
@ -285,16 +285,20 @@ const debounceMap = new WeakMap();
|
|||||||
*/
|
*/
|
||||||
export function debounce(func, timeout = debounce_timeout.standard) {
|
export function debounce(func, timeout = debounce_timeout.standard) {
|
||||||
let timer;
|
let timer;
|
||||||
return (...args) => {
|
let fn = (...args) => {
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
timer = setTimeout(() => { func.apply(this, args); }, timeout);
|
timer = setTimeout(() => { func.apply(this, args); }, timeout);
|
||||||
debounceMap.set(func, timer);
|
debounceMap.set(func, timer);
|
||||||
|
debounceMap.set(fn, timer);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancels a scheduled debounced function. Does nothing if the function is not debounced or not scheduled.
|
* Cancels a scheduled debounced function.
|
||||||
* @param {function} func The function to cancel.
|
* Does nothing if the function is not debounced or not scheduled.
|
||||||
|
* @param {function} func The function to cancel. Either the original or the debounced function.
|
||||||
*/
|
*/
|
||||||
export function cancelDebounce(func) {
|
export function cancelDebounce(func) {
|
||||||
if (debounceMap.has(func)) {
|
if (debounceMap.has(func)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user