added debounced function in the editor

This commit is contained in:
Akhilesh Rangani
2024-06-13 15:50:47 +00:00
committed by James Murdza
parent e5b320d1c5
commit 0df074924f
2 changed files with 65 additions and 35 deletions

View File

@ -61,3 +61,13 @@ export function addNew(
])
}
}
export function debounce<T extends (...args: any[]) => void>(func: T, wait: number): T {
let timeout: NodeJS.Timeout | null = null;
return function (...args: Parameters<T>) {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(() => func(...args), wait);
} as T;
}