let timeout = null;
function debounce(func, wait = 500, immediate = false) {
if (timeout !== null) clearTimeout(timeout);
if (immediate) {
var callNow = !timeout;
timeout = setTimeout(function() {
timeout = null;
}, wait);
if (callNow) typeof func === 'function' && func();
} else {
timeout = setTimeout(function() {
typeof func === 'function' && func();
}, wait);
}
}
export default debounce
export function debounce (fn, ms = 500) {
let debounceTimer = null;
return function (...args) {
if(debounceTimer) clearTimeout(debounceTimer);
debounceTimer = setTimeout(() => {
fn.apply(this, args);
}, ms);
};
}