/** @license Copyright (c) 2022 trading_peter This program is available under Apache License Version 2.0 */ export const debounce = (cb, delay, immediate) => { let timeout; return (...a) => { const callNow = immediate && !timeout; clearTimeout(timeout); timeout = setTimeout(() => { timeout = null; if (!immediate) cb.apply(this, a); }, delay); if (callNow) cb.apply(this, a); }; };