chore: editor resizing debounce

This commit is contained in:
dongchengjie
2024-07-08 23:18:06 +08:00
parent df6e245e5c
commit 49e36b6e00
2 changed files with 23 additions and 10 deletions

12
src/utils/debounce.ts Normal file
View File

@@ -0,0 +1,12 @@
export default function debounce<T extends (...args: any[]) => void>(
func: T,
wait: number
): T {
let timeout: ReturnType<typeof setTimeout> | null = null;
return function (this: any, ...args: Parameters<T>) {
if (timeout !== null) {
clearTimeout(timeout);
}
timeout = setTimeout(() => func.apply(this, args), wait);
} as T;
}