UNPKG

@ng-doc/builder

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>

28 lines 1.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CachedEntity = CachedEntity; const core_1 = require("@ng-doc/core"); const helpers_1 = require("../helpers"); /** * Decorator for cached entities, it will load the cache and assign the properties to the entity */ function CachedEntity() { // eslint-disable-next-line @typescript-eslint/no-unused-vars return (Value, _context) => { return class extends Value { constructor(...args) { super(...args); const cache = (0, helpers_1.loadCache)(this.id); (0, core_1.asArray)(this.__cachedProps?.keys()).forEach((property) => { const accessor = this.__cachedProps?.get(property); // @ts-expect-error - We are using the property as a key const value = cache.data?.[property]; if (Object.keys(cache?.data ?? {}).includes(property) && accessor) { Object.assign(this, { [property]: accessor.get(value) }); } }); } }; }; } //# sourceMappingURL=cached-entity.js.map