Created
October 19, 2018 10:16
-
-
Save steevehook/b7059059787d322b9377aeaae34e4a84 to your computer and use it in GitHub Desktop.
Function debouncer
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 default (delay, fn) => { | |
let timerId; | |
return function (...args) { | |
if (timerId) { | |
clearTimeout(timerId); | |
} | |
timerId = setTimeout(() => { | |
fn(...args); | |
timerId = null; | |
}, delay); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment