mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
parent
41cc656fcf
commit
69754bf382
@ -1,18 +1 @@
|
||||
export const fakeDelay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
||||
|
||||
export const debounce = (func, delay, immediate) => {
|
||||
let timerId;
|
||||
return (...args) => {
|
||||
const boundFunc = func.bind(this, ...args);
|
||||
clearTimeout(timerId);
|
||||
if (immediate && !timerId) {
|
||||
boundFunc();
|
||||
}
|
||||
const calleeFunc = immediate
|
||||
? () => {
|
||||
timerId = null;
|
||||
}
|
||||
: boundFunc;
|
||||
timerId = setTimeout(calleeFunc, delay);
|
||||
};
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user