UNPKG

plus-midwayjs

Version:
33 lines (32 loc) 1.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Event = exports.PLUS_EVENT_KEY = exports.PlusEvent = exports.PLUS_CLS_EVENT_KEY = void 0; const core_1 = require("@midwayjs/core"); exports.PLUS_CLS_EVENT_KEY = 'decorator:plus:cls:event'; function PlusEvent() { return (target) => { // 将装饰的类,绑定到该装饰器,用于后续能获取到 class (0, core_1.saveModule)(exports.PLUS_CLS_EVENT_KEY, target); // 保存一些元数据信息,任意你希望存的东西 (0, core_1.saveClassMetadata)(exports.PLUS_CLS_EVENT_KEY, {}, target); // 指定 IoC 容器创建实例的作用域,这里注册为请求作用域,这样能取到 ctx (0, core_1.Scope)(core_1.ScopeEnum.Singleton)(target); }; } exports.PlusEvent = PlusEvent; exports.PLUS_EVENT_KEY = 'decorator:plus:event'; /** * 事件 * @param eventName * @constructor */ function Event(eventName) { return (target, propertyKey, descriptor) => { (0, core_1.attachClassMetadata)(exports.PLUS_EVENT_KEY, { eventName, propertyKey, descriptor }, target); }; } exports.Event = Event;