Skip to content

Instantly share code, notes, and snippets.

@mrchief
Created May 27, 2018 23:11
Show Gist options
  • Save mrchief/a7e8938ee96774f05644905b37f09536 to your computer and use it in GitHub Desktop.
Save mrchief/a7e8938ee96774f05644905b37f09536 to your computer and use it in GitHub Desktop.
const debounce = (func, wait, immediate) => {
let timeout
return (...args) => {
const later = () => {
timeout = null
if (!immediate) func(...args)
}
const callNow = immediate && !timeout
clearTimeout(timeout)
timeout = setTimeout(later, wait)
if (callNow) func(...args)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment