Last active
July 13, 2018 14:01
-
-
Save t-davies/24a2e3773fb39b9b67eadf946d97d01b to your computer and use it in GitHub Desktop.
Debounce with arguments support
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
/* @flow */ | |
export function debounce(callback: () => mixed, timeout: number) { | |
let activeTimeout; | |
return function() { | |
if (activeTimeout) { | |
clearTimeout(activeTimeout); | |
} | |
activeTimeout = setTimeout( | |
() => callback.apply(null, arguments), | |
timeout); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment