Created
September 14, 2023 01:21
-
-
Save ztrehagem/db2ebce9101ce3fe52d9a2ab9c68c3f0 to your computer and use it in GitHub Desktop.
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
// eslint-disable-next-line @typescript-eslint/no-explicit-any | |
export const debounce = <T extends (...args: any[]) => void>( | |
fn: T, | |
timeout: number, | |
): T => { | |
let timeoutId: number | undefined; | |
return new Proxy(fn, { | |
apply: (target, thisArg, args) => { | |
window.clearInterval(timeoutId); | |
timeoutId = window.setTimeout(() => { | |
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | |
target.call(thisArg, ...args); | |
}, timeout); | |
}, | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment