UNPKG

tsioc

Version:

tsioc is AOP, Ioc container, via typescript decorator

65 lines (63 loc) 2.85 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); var index_1 = require("../core/index"); var index_2 = require("../utils/index"); var index_3 = require("./decorators/index"); /** * for global aop advisor. * * @export * @class Advisor */ var Advisor = /** @class */ (function () { function Advisor(container) { this.container = container; this.aspects = new index_2.MapSet(); this.advices = new index_2.MapSet(); } Advisor.prototype.setAdvices = function (key, advices) { if (!this.advices.has(key)) { this.advices.set(key, advices); } }; Advisor.prototype.getAdvices = function (key) { if (!this.advices.has(key)) { return null; } return this.advices.get(key); }; Advisor.prototype.hasRegisterAdvices = function (targetType) { var _this = this; var methods = Object.keys(Object.getOwnPropertyDescriptors(targetType.prototype)); var className = targetType.name || targetType.constructor.name; return methods.some(function (m) { return _this.advices.has(className + "." + m); }); }; Advisor.prototype.add = function (aspect) { if (!this.aspects.has(aspect)) { var metas = index_1.getOwnMethodMetadata(index_3.Advice, aspect); this.aspects.set(aspect, metas); } }; Advisor.classAnnations = { "name": "Advisor", "params": { "constructor": ["container"], "setAdvices": ["key", "advices"], "getAdvices": ["key"], "hasRegisterAdvices": ["targetType"], "add": ["aspect"] } }; Advisor = __decorate([ index_1.NonePointcut(), index_1.Singleton(index_2.symbols.IAdvisor), __param(0, index_1.Inject(index_2.symbols.IContainer)), __metadata("design:paramtypes", [Object]) ], Advisor); return Advisor; }()); exports.Advisor = Advisor; //# sourceMappingURL=sourcemaps/Advisor.js.map