@empathyco/x-components
Version:
Empathy X Components
27 lines (25 loc) • 658 B
JavaScript
/**
* 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