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.

21 lines 644 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Once = void 0; /** * @public * Method decorator. The target will be called only once, subsequent calls will return the first return. */ 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; }; } exports.Once = Once; //# sourceMappingURL=once.js.map