Skip to content

Instantly share code, notes, and snippets.

@wesleybliss
Created December 17, 2020 15:10
Show Gist options
  • Save wesleybliss/72a2f1c6fb9867fba3b818b2a3141276 to your computer and use it in GitHub Desktop.
Save wesleybliss/72a2f1c6fb9867fba3b818b2a3141276 to your computer and use it in GitHub Desktop.
Debounce #js
export function debounce(func, wait, immediate) {
let timeout
return function (...args) {
clearTimeout(timeout)
timeout = setTimeout(() => {
timeout = null
if (!immediate) func.apply(this, args)
}, wait)
if (immediate && !timeout) func.apply(this, [...args])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment