UNPKG

quasar

Version:

Build high-performance VueJS user interfaces (SPA, PWA, SSR, Mobile and Desktop) in record time

30 lines (23 loc) 579 B
// oxlint-disable-next-line default-param-last export default function debounce(fn, wait = 250, immediate) { let timer = null function debounced(/* ...args */) { const args = arguments const later = () => { timer = null if (immediate !== true) { fn.apply(this, args) } } if (timer !== null) { clearTimeout(timer) } else if (immediate === true) { fn.apply(this, args) } timer = setTimeout(later, wait) } debounced.cancel = () => { if (timer !== null) clearTimeout(timer) } return debounced }