UNPKG

typedash

Version:

modern, type-safe collection of utility functions

38 lines (37 loc) 892 B
// src/functions/debounce/debounce.ts function debounce(func, delay, options = {}) { let timeoutId = null; let isCalled = false; let latestArguments; function debouncedFunction(...args) { latestArguments = args; if (options.leading && !isCalled) { func(...args); isCalled = true; } if (timeoutId !== null) { clearTimeout(timeoutId); } timeoutId = setTimeout(() => { if (!options.leading) { func(...args); } isCalled = false; }, delay); } debouncedFunction.flush = () => { if (timeoutId !== null) { clearTimeout(timeoutId); } func(...latestArguments); }; debouncedFunction.clear = () => { if (timeoutId !== null) { clearTimeout(timeoutId); } }; return debouncedFunction; } export { debounce }; //# sourceMappingURL=out.js.map //# sourceMappingURL=chunk-F43JFOHS.js.map