ref(toolbar): replace custom debounce with lodash throttle

The current custom debounce function sets a timeout and ensures
additional calls are not executed while the timeout is pending.
Regulating the call of a function while also ensuring it gets
called at a certain time is a throttle.
This commit is contained in:
Leonard Kim
2017-08-21 17:20:52 -07:00
parent 28b4595561
commit ec7c10c99b
2 changed files with 5 additions and 34 deletions
-30
View File
@@ -16,36 +16,6 @@ export function createDeferred() {
return deferred;
}
/**
* Creates a debounced function that delays invoking func until after wait
* milliseconds have elapsed since the last time the debounced function was
* invoked.
*
* @param fn
* @param wait
* @param options
* @returns {function(...[*])}
*/
export function debounce(fn, wait = 0, options = {}) {
const leading = options.leading || false;
const trailing
= (typeof options.trailing === 'undefined') || options.trailing;
let called = false;
return (...args) => {
if (!called) {
leading && fn(...args);
setTimeout(() => {
called = false;
trailing && fn(...args);
}, wait);
called = true;
}
};
}
/**
* Returns the namespace for all global variables, functions, etc that we need.
*