Skip to content

Instantly share code, notes, and snippets.

@t-davies
Last active July 13, 2018 14:01
Show Gist options
  • Save t-davies/24a2e3773fb39b9b67eadf946d97d01b to your computer and use it in GitHub Desktop.
Save t-davies/24a2e3773fb39b9b67eadf946d97d01b to your computer and use it in GitHub Desktop.
Debounce with arguments support
/* @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