UNPKG

quasar-framework

Version:

Build responsive SPA, SSR, PWA, Hybrid Mobile Apps and Electron apps, all simultaneously using the same codebase

25 lines (20 loc) 433 B
export default function (fn, wait = 250, immediate) { let timeout function debounced (...args) { const later = () => { timeout = null if (!immediate) { fn.apply(this, args) } } clearTimeout(timeout) if (immediate && !timeout) { fn.apply(this, args) } timeout = setTimeout(later, wait) } debounced.cancel = () => { clearTimeout(timeout) } return debounced }