UNPKG

chin-utils

Version:
22 lines (18 loc) 429 B
export default (fn, delay = 300, immediate, props) => { let timer = null; let myDebounce = function () { const args = [...arguments, props]; timer && clearTimeout(timer); if (immediate) { !timer && fn.apply(this, args); timer = setTimeout(() => { timer = null; }, delay); } else { timer = setTimeout(() => { fn.apply(this, args); }, delay); } }; return myDebounce; };