Created
December 28, 2022 15:23
-
-
Save moonformeli/5ed7dd8469ece82925a7ba6a4e73593c to your computer and use it in GitHub Desktop.
debounce.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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