UNPKG

@web-atoms/core-docs

Version:
98 lines 3.89 kB
(function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define(["require", "exports", "./TypeKey"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Inject = exports.InjectedTypes = void 0; const TypeKey_1 = require("./TypeKey"); class InjectedTypes { static getParamList(key, typeKey1) { let plist = InjectedTypes.paramList[typeKey1]; // We need to find @Inject for base types if // current type does not define any constructor let type = key; while (plist === undefined) { type = Object.getPrototypeOf(type); if (!type) { break; } const typeKey = TypeKey_1.TypeKey.get(type); plist = InjectedTypes.paramList[typeKey]; if (!plist) { InjectedTypes.paramList[typeKey] = plist; } } return plist; } static getPropertyList(key, typeKey1) { let plist = InjectedTypes.propertyList[typeKey1]; // We need to find @Inject for base types if // current type does not define any constructor let type = key; while (plist === undefined) { type = Object.getPrototypeOf(type); if (!type) { break; } const typeKey = TypeKey_1.TypeKey.get(type); plist = InjectedTypes.propertyList[typeKey]; if (!plist) { InjectedTypes.propertyList[typeKey] = plist; } } return plist; } } exports.InjectedTypes = InjectedTypes; InjectedTypes.paramList = {}; InjectedTypes.propertyList = {}; // export function Inject(target: any, name: string): void; function Inject(target, name, index) { if (index !== undefined) { const key = TypeKey_1.TypeKey.get(target); const plist = Reflect.getMetadata("design:paramtypes", target, name); if (typeof index === "number") { const pSavedList = InjectedTypes.paramList[key] || (InjectedTypes.paramList[key] = []); pSavedList[index] = plist[index]; } else { throw new Error("Inject can only be applied on constructor" + "parameter or a property without get/set methods"); } } else { const key = TypeKey_1.TypeKey.get(target.constructor); const plist = Reflect.getMetadata("design:type", target, name); const p = InjectedTypes.propertyList[key] || (InjectedTypes.propertyList[key] = {}); p[name] = plist; // need to merge base properties.. let base = target.constructor; while (true) { base = Object.getPrototypeOf(base); if (!base) { break; } const baseKey = TypeKey_1.TypeKey.get(base); const bp = InjectedTypes.propertyList[baseKey]; if (bp) { for (const pKey in bp) { if (bp.hasOwnProperty(pKey)) { const element = bp[pKey]; if (!p[pKey]) { p[pKey] = element; } } } } } } } exports.Inject = Inject; }); //# sourceMappingURL=Inject.js.map