Add debounce file [SCI-8300] (#5419)

This commit is contained in:
artoscinote 2023-05-17 12:00:37 +02:00 committed by GitHub
parent 5a06f649d6
commit a52ee99781
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -0,0 +1,12 @@
export function debounce(fn, wait){
let timer;
return function(...args){
if(timer) {
clearTimeout(timer); // clear any pre-existing timer
}
const context = this; // get the current context
timer = setTimeout(()=>{
fn.apply(context, args); // call the function if time expires
}, wait);
}
}