Skip to content

Instantly share code, notes, and snippets.

@jonasraoni
Created March 30, 2019 19:40
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 jonasraoni/4919f9e1698e77a5b675eb9375e46c8d to your computer and use it in GitHub Desktop.
Save jonasraoni/4919f9e1698e77a5b675eb9375e46c8d to your computer and use it in GitHub Desktop.
Debounce
//+ Jonas Raoni Soares Silva
//@ http://raoni.org
export default function debounce (action, delay) {
let handle;
return function (...args) {
if (handle) {
clearTimeout(handle);
handle = null;
}
handle = setTimeout(() => action.call(this, ...args), delay);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment