UI bug fixes
This commit is contained in:
@@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user