Skip to content

Instantly share code, notes, and snippets.

@a-bronx
Forked from just-boris/debounce.js
Created June 2, 2020 07:01
Show Gist options
  • Select an option

  • Save a-bronx/7c78b99f1782f0ce9350617f9c2e4afb to your computer and use it in GitHub Desktop.

Select an option

Save a-bronx/7c78b99f1782f0ce9350617f9c2e4afb to your computer and use it in GitHub Desktop.
small debounce implementation without lodash
export const DEBOUNCE_DEFAULT_DELAY = 200;
export default function debounce(func, delay = DEBOUNCE_DEFAULT_DELAY) {
let timeout;
return function(...args) {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(() => {
timeout = null;
func.apply(this, args);
}, delay);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment