Created
October 28, 2018 04:52
-
-
Save cyan33/33b69c7140dee48484ff96133e7ef353 to your computer and use it in GitHub Desktop.
a simple debounce implementation
This file contains hidden or 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
// I bounced into this debounce implementation today and | |
// think it's actually quite easy and simple | |
function debounce(fn, ms = 1000) { | |
let timeout = null; | |
return (...args) => { | |
if (timeout) { | |
clearTimeout(timeout); | |
} | |
timeout = setTimeout(() => fn(...args), ms); | |
} | |
} | |
module.exports = debounce; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment