mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-27 02:04:33 +08:00
Add debounce file [SCI-8300] (#5419)
This commit is contained in:
parent
5a06f649d6
commit
a52ee99781
1 changed files with 12 additions and 0 deletions
12
app/javascript/vue/shared/debounce.js
Normal file
12
app/javascript/vue/shared/debounce.js
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue