Skip to content

Instantly share code, notes, and snippets.

@JasonStoltz
Created January 15, 2019 18:11
Show Gist options
  • Select an option

  • Save JasonStoltz/9cddcc63f5eacf5258ed86b2406e8cbe to your computer and use it in GitHub Desktop.

Select an option

Save JasonStoltz/9cddcc63f5eacf5258ed86b2406e8cbe to your computer and use it in GitHub Desktop.
Debounce 1 tick
const debounce = (() => {
let wasCalled = false;
let fn = null;
return newFn => {
fn = newFn;
if (!wasCalled) {
wasCalled = true;
setTimeout(() => {
wasCalled = false;
return fn();
});
}
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment