UNPKG

type-autofac

Version:

tsioc is AOP, Ioc container, via typescript decorator

99 lines (97 loc) 4.48 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var index_1 = require("../../core/index"); var index_2 = require("../../utils/index"); var AopActions_1 = require("./AopActions"); var isValideAspectTarget_1 = require("../isValideAspectTarget"); var MatchPointcutAction = /** @class */ (function (_super) { __extends(MatchPointcutAction, _super); function MatchPointcutAction() { return _super.call(this, AopActions_1.AopActions.matchPointcut) || this; } MatchPointcutAction.prototype.working = function (container, data) { var _this = this; // aspect class do nothing. if (!isValideAspectTarget_1.isValideAspectTarget(data.targetType)) { return; } var aspectmgr = container.get(index_2.symbols.IAdvisor); var matcher = container.get(index_2.symbols.IAdviceMatcher); aspectmgr.aspects.forEach(function (adviceMetas, type) { var matchpoints = matcher.match(type, data.targetType, adviceMetas); matchpoints.forEach(function (mpt) { var fullName = mpt.fullName; var advice = mpt.advice; var advices = aspectmgr.getAdvices(fullName); if (!advices) { advices = { Before: [], Pointcut: [], After: [], Around: [], AfterThrowing: [], AfterReturning: [] }; aspectmgr.setAdvices(fullName, advices); } var advicer = Object.assign(mpt, { aspectType: type }); if (advice.adviceName === 'Before') { if (!advices.Before.some(function (a) { return _this.isAdviceEquals(a.advice, advice); })) { advices.Before.push(advicer); } } else if (advice.adviceName === 'Pointcut') { if (!advices.Pointcut.some(function (a) { return _this.isAdviceEquals(a.advice, advice); })) { advices.Pointcut.push(advicer); } } else if (advice.adviceName === 'Around') { if (!advices.Around.some(function (a) { return _this.isAdviceEquals(a.advice, advice); })) { advices.Around.push(advicer); } } else if (advice.adviceName === 'After') { if (!advices.After.some(function (a) { return _this.isAdviceEquals(a.advice, advice); })) { advices.After.push(advicer); } } else if (advice.adviceName === 'AfterThrowing') { if (!advices.AfterThrowing.some(function (a) { return _this.isAdviceEquals(a.advice, advice); })) { advices.AfterThrowing.push(advicer); } } else if (advice.adviceName === 'AfterReturning') { if (!advices.AfterReturning.some(function (a) { return _this.isAdviceEquals(a.advice, advice); })) { advices.AfterReturning.push(advicer); } } }); }); }; MatchPointcutAction.prototype.isAdviceEquals = function (advice1, advice2) { if (!advice1 || !advice2) { return false; } if (advice1 === advice2) { return true; } return advice1.adviceName === advice2.adviceName && advice1.pointcut === advice2.pointcut && advice1.propertyKey === advice2.propertyKey; }; return MatchPointcutAction; }(index_1.ActionComposite)); exports.MatchPointcutAction = MatchPointcutAction; //# sourceMappingURL=../../sourcemaps/aop/actions/MatchPointcutAction.js.map