Skip to content

Instantly share code, notes, and snippets.

@steevehook
Created October 19, 2018 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steevehook/b7059059787d322b9377aeaae34e4a84 to your computer and use it in GitHub Desktop.
Save steevehook/b7059059787d322b9377aeaae34e4a84 to your computer and use it in GitHub Desktop.
Function debouncer
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