UNPKG

@empathyco/x-components

Version:
27 lines (25 loc) 658 B
/** * Util function that returns a throttled version of the function passed as parameter. * * @param fn - Function to be debounced. * @param throttleTimeMs - The time of throttle in ms. * @returns A new function with the throttle. * * @public */ const throttle = (fn, throttleTimeMs) => { let timeout; let params; const throttleFn = (...args) => { params = args; if (!timeout) { timeout = setTimeout(() => { fn(...params); timeout = undefined; }, throttleTimeMs); } }; return throttleFn; }; export { throttle }; //# sourceMappingURL=throttle.js.map