Add debounce to pg parameters search filter (#14140)

* Add debounce to pg parameters search filter

* Update tsconfig
This commit is contained in:
Charles Gagnon
2021-02-02 16:15:31 -08:00
committed by GitHub
parent 661e7c361d
commit 86a5cb27b7
3 changed files with 45 additions and 6 deletions

View File

@@ -295,3 +295,35 @@ export async function tryExecuteAction<T>(action: () => T | PromiseLike<T>): Pro
}
return { result, error };
}
function decorate(decorator: (fn: Function, key: string) => Function): Function {
return (_target: any, key: string, descriptor: any) => {
let fnKey: string | null = null;
let fn: Function | null = null;
if (typeof descriptor.value === 'function') {
fnKey = 'value';
fn = descriptor.value;
} else if (typeof descriptor.get === 'function') {
fnKey = 'get';
fn = descriptor.get;
}
if (!fn || !fnKey) {
throw new Error('not supported');
}
descriptor[fnKey] = decorator(fn, key);
};
}
export function debounce(delay: number): Function {
return decorate((fn, key) => {
const timerKey = `$debounce$${key}`;
return function (this: any, ...args: any[]) {
clearTimeout(this[timerKey]);
this[timerKey] = setTimeout(() => fn.apply(this, args), delay);
};
});
}