cytoscape-expand-collapse
Version:
This extension provides an interface to expand-collapse nodes.
32 lines (31 loc) • 939 B
JavaScript
var debounce2 = (function () {
/**
* Slightly modified version of debounce. Calls fn2 at the beginning of frequent calls to fn1
* @static
* @category Function
* @param {Function} fn1 The function to debounce.
* @param {number} [wait=0] The number of milliseconds to delay.
* @param {Function} fn2 The function to call the beginning of frequent calls to fn1
* @returns {Function} Returns the new debounced function.
*/
function debounce2(fn1, wait, fn2) {
let timeout;
let isInit = true;
return function () {
const context = this, args = arguments;
const later = function () {
timeout = null;
fn1.apply(context, args);
isInit = true;
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (isInit) {
fn2.apply(context, args);
isInit = false;
}
};
}
return debounce2;
})();
module.exports = debounce2;