mirror of
https://github.com/zadam/trilium.git
synced 2025-11-19 23:24:25 +01:00
11 lines
418 B
TypeScript
11 lines
418 B
TypeScript
export default function debounce<T extends (...args: unknown[]) => unknown>(executor: T, delay: number) {
|
|
let timeout: NodeJS.Timeout | null;
|
|
return function(...args: Parameters<T>): void {
|
|
const callback = () => {
|
|
timeout = null;
|
|
Reflect.apply(executor, null, args);
|
|
};
|
|
if (timeout) clearTimeout(timeout);
|
|
timeout = setTimeout(callback, delay);
|
|
};
|
|
} |