global: snapshot

This commit is contained in:
nym21
2026-01-19 16:52:17 +01:00
parent c90953adbe
commit 371ff86287
23 changed files with 1043 additions and 908 deletions

View File

@@ -36,3 +36,23 @@ export function throttle(callback, wait = 1000) {
}
};
}
/**
* @template {(...args: any[]) => any} F
* @param {F} callback
* @param {number} [wait]
*/
export function debounce(callback, wait = 1000) {
/** @type {number | null} */
let timeoutId = null;
return (/** @type {Parameters<F>} */ ...args) => {
if (timeoutId) {
clearTimeout(timeoutId);
}
timeoutId = setTimeout(() => {
callback(...args);
timeoutId = null;
}, wait);
};
}