UNPKG

@carbon/ibm-products

Version:

Carbon for IBM Products

33 lines (29 loc) 774 B
/** * Copyright IBM Corp. 2020, 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. */ 'use strict'; const debounce = function (func, delay) { let leading = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; let timeout; return function () { for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } if (timeout) { clearTimeout(timeout); } if (leading && !timeout) { func(...args); } timeout = setTimeout(() => { timeout = null; if (!leading) { func(...args); } }, delay); }; }; exports.debounce = debounce;