Skip to content

Instantly share code, notes, and snippets.

@moonformeli
Created December 28, 2022 15:23
Show Gist options
  • Save moonformeli/5ed7dd8469ece82925a7ba6a4e73593c to your computer and use it in GitHub Desktop.
Save moonformeli/5ed7dd8469ece82925a7ba6a4e73593c to your computer and use it in GitHub Desktop.
debounce.ts
type Fn = (...args) => any;
function debounce(fn: Fn, delay: number = 200) {
let timer: NodeJS.Timeout = null;
return ((...args) => {
if (timer) {
clearTimeout(timer);
timer = null;
}
timer = setTimeout(() => {}, delay);
}) as Fn;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment