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.
15 lines (14 loc) • 495 B
JavaScript
export 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;
};