Skip to content

Instantly share code, notes, and snippets.

@gribnoysup
Last active April 24, 2018 09:31
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 gribnoysup/1cf1f7d6e553f96ed65fcfb68f800098 to your computer and use it in GitHub Desktop.
Save gribnoysup/1cf1f7d6e553f96ed65fcfb68f800098 to your computer and use it in GitHub Desktop.
export const debounce = (fn, delay = 0, context = null) => {
let timeout = null;
const debounced = (...args) => {
clearTimeout(timeout);
timeout = setTimeout(() => fn.apply(context, args), delay);
};
debounced.cancel = () => clearTimeout(timeout);
return debounced;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment