// Debounce - II
export default function debounce(func, wait) {
let timerId, args, self;
function debouncedFunction() {
args = arguments;
self = this;
clearTimeout(timerId);
timerId = setTimeout(() => {
func.apply(self, args);
args = null;
}, wait)
}
debouncedFunction.cancel = function() {
clearTimeout(timerId);
args = null;
}
debouncedFunction.flush = function() {
clearTimeout(timerId);
if(args)
func.apply(self, args);
}
return debouncedFunction;
}