mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-11 15:16:28 +08:00
7c2574b1ca
Co-authored-by: Himself65 <himself65@outlook.com>
20 lines
393 B
TypeScript
20 lines
393 B
TypeScript
export function debounce<T extends (...args: any[]) => void>(
|
|
fn: T,
|
|
delay: number
|
|
) {
|
|
let timeoutId: NodeJS.Timer | undefined;
|
|
return (...args: Parameters<T>) => {
|
|
if (timeoutId) {
|
|
clearTimeout(timeoutId);
|
|
}
|
|
timeoutId = setTimeout(() => {
|
|
fn(...args);
|
|
timeoutId = undefined;
|
|
}, delay);
|
|
};
|
|
}
|
|
|
|
export function ts() {
|
|
return new Date().getTime();
|
|
}
|