Last active
April 24, 2018 09:31
-
-
Save gribnoysup/1cf1f7d6e553f96ed65fcfb68f800098 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const debounce = (fn, delay = 0, context = null) => { | |
let timeout = null; | |
const debounced = (...args) => { | |
clearTimeout(timeout); | |
timeout = setTimeout(() => fn.apply(context, args), delay); | |
}; | |
debounced.cancel = () => clearTimeout(timeout); | |
return debounced; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment