UNPKG

@ng-doc/ui-kit

Version:

<!-- PROJECT LOGO --> <br /> <div align="center"> <a href="https://github.com/ng-doc/ng-doc"> <img src="https://ng-doc.com/assets/images/ng-doc.svg?raw=true" alt="Logo" height="150px"> </a>

54 lines (51 loc) 1.76 kB
/* eslint-disable */ /** * Implements lazy initialization for getter or memoization of a function call similar to pure {@link: Pipe}. * Replaces getter with its calculated value upon first call or keeps track of last call arguments and returned * value for function, skipping calculation when arguments are strictly the same. * * @throws error if used not on getter or function * * CAUTION: `this` is not available inside such functions/getters, they must be pure. */ function ngDocMakePure(_target, propertyKey, { get, enumerable, value }) { if (get) { return { enumerable, get() { const value = get.call(this); Object.defineProperty(this, propertyKey, { enumerable, value }); return value; }, }; } if (typeof value !== 'function') { throw new Error('ngDocMakePure can only be used with functions or getters'); } const original = value; return { enumerable, get() { let previousArgs = []; let previousResult; const patched = (...args) => { if (previousArgs.length === args.length && args.every((arg, index) => arg === previousArgs[index])) { return previousResult; } previousArgs = args; previousResult = original.apply(this, args); return previousResult; }; Object.defineProperty(this, propertyKey, { value: patched, }); return patched; }, }; } /** * Generated bundle index. Do not edit. */ export { ngDocMakePure }; //# sourceMappingURL=ng-doc-ui-kit-decorators.mjs.map