feat: debounce creator + general improvements

This commit is contained in:
SethBurkart123
2025-03-28 00:14:29 +11:00
parent 5413286f56
commit ad2ad4d456
5 changed files with 22 additions and 5 deletions
+7
View File
@@ -0,0 +1,7 @@
export default function debounce<T extends (...args: any[]) => void>(fn: T, delay: number): (...args: Parameters<T>) => void {
let timeout: ReturnType<typeof setTimeout>;
return function(this: ThisParameterType<T>, ...args: Parameters<T>) {
clearTimeout(timeout);
timeout = setTimeout(() => fn.apply(this, args), delay);
};
}