UNPKG

@carbon/ibm-products

Version:
28 lines (26 loc) 707 B
/** * Copyright IBM Corp. 2020, 2026 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ //#region src/global/js/utils/debounce.ts /** * Copyright IBM Corp. 2025, 2025 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ const debounce = (func, delay, leading = true) => { let timeout; return (...args) => { if (timeout) clearTimeout(timeout); if (leading && !timeout) func(...args); timeout = setTimeout(() => { timeout = null; if (!leading) func(...args); }, delay); }; }; //#endregion exports.debounce = debounce;