@zendesk/react-measure-timing-hooks
Version:
react hooks for measuring time to interactive and time to render of components
22 lines • 728 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.throttle = void 0;
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable prefer-spread */
const throttle = (func, waitFor) => {
let previouslyRun;
let queuedToRun;
return function invokeFn(...args) {
const now = Date.now();
clearTimeout(queuedToRun);
if (!previouslyRun || now - previouslyRun >= waitFor) {
func.apply(null, args);
previouslyRun = now;
}
else {
queuedToRun = setTimeout(() => void invokeFn(...args), waitFor - (now - previouslyRun));
}
};
};
exports.throttle = throttle;
//# sourceMappingURL=throttle.js.map
;