Skip to content

Instantly share code, notes, and snippets.

@just-boris
Created May 31, 2020 12:16
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save just-boris/c298b257727acc238c03631b8a27aae7 to your computer and use it in GitHub Desktop.
Save just-boris/c298b257727acc238c03631b8a27aae7 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