mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 17:15:38 +08:00
chore: editor resizing debounce
This commit is contained in:
12
src/utils/debounce.ts
Normal file
12
src/utils/debounce.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user