UNPKG

@vime-js/utils

Version:
18 lines (14 loc) 433 B
export const debounce = (func, wait, immediate) => { let timeout; return function executedFunction(...args) { const context = this; const later = function delayedFunctionCall() { timeout = null; if (!immediate) func.apply(context, args); }; const callNow = immediate && !timeout; clearTimeout(timeout); timeout = setTimeout(later, wait); if (callNow) func.apply(context, args); }; };