UNPKG

@dartbot/dartboard

Version:

Dartboard implemented as a vanilla web component

27 lines 774 B
export const debounce = (func, delay, options) => { let timeout; let leadingCall = false; let trailingCall = false; const debounced = (...args) => { if (timeout) { clearTimeout(timeout); } if (options?.leading && !leadingCall) { func(...args); leadingCall = true; } timeout = setTimeout(() => { if (options?.trailing && leadingCall) { func(...args); } leadingCall = false; trailingCall = false; }, delay); if (options?.trailing && !leadingCall && !trailingCall) { func(...args); trailingCall = true; } }; return debounced; }; //# sourceMappingURL=debounce.js.map