UNPKG

rc-js-util

Version:

A collection of TS and C++ utilities to help writing performant and correct applications, achieved through strict typing and (removable) invariant checking.

17 lines 530 B
/** * @public * Method decorator. The target will be called only once, subsequent calls will return the first return. */ export function Once(target, key, descriptor) { const original = target[key]; const results = new WeakMap(); target[key] = descriptor.value = function (...args) { if (results.has(this)) { return results.get(this); } const result = original.apply(this, args); results.set(this, result); return result; }; } //# sourceMappingURL=once.js.map