ts-ioc-container
Version:
Fast, lightweight TypeScript dependency injection container with a clean API, scoped lifecycles, decorators, tokens, hooks, lazy injection, customizable providers, and no global container objects.
19 lines (18 loc) • 621 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.throttle = void 0;
const throttle = (ms) => (target, propertyKey, descriptor) => {
const originalMethod = descriptor.value;
const lastCalledMap = new WeakMap();
descriptor.value = function (...args) {
const now = Date.now();
const lastCalled = lastCalledMap.get(this) ?? -Infinity;
if (now - lastCalled < ms) {
return undefined;
}
lastCalledMap.set(this, now);
return originalMethod.apply(this, args);
};
return descriptor;
};
exports.throttle = throttle;