Improve sorting behavior by adding delay

This commit is contained in:
Divya Jagadish authored and Zaid Abdulla committed 2022-04-08 13:08:41 -07:00
1 parent 7941d929d2
commit dabf1b2f43
10 files changed
+75 -87

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
export default function debounce<T>(
func: (args: T[]) => void,
timeout: number
): (arg: T) => void {
let timer: ReturnType<typeof setTimeout>;
let args: T[] = [];
return (arg: T) => {
args.push(arg);
clearTimeout(timer);
timer = setTimeout(() => {
const argscopy = args;
args = [];
func(argscopy);
}, timeout);
};
}