UI bug fixes

This commit is contained in:
Stijnus
2025-02-18 14:13:13 +01:00
parent 6e89710ec7
commit 0e60d9cca8
9 changed files with 133 additions and 116 deletions

View File

@@ -1,17 +1,13 @@
export function debounce<Args extends any[]>(fn: (...args: Args) => void, delay = 100) {
if (delay === 0) {
return fn;
}
export function debounce<T extends (...args: any[]) => any>(func: T, wait: number): (...args: Parameters<T>) => void {
let timeout: NodeJS.Timeout;
let timer: number | undefined;
return function executedFunction(...args: Parameters<T>) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
return function <U>(this: U, ...args: Args) {
const context = this;
clearTimeout(timer);
timer = window.setTimeout(() => {
fn.apply(context, args);
}, delay);
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}