UNPKG

@robotlegsjs/core

Version:

An architecture-based IoC framework for JavaScript/TypeScript

81 lines 3.86 kB
"use strict"; // ------------------------------------------------------------------------------ // Copyright (c) 2017-present, RobotlegsJS. All Rights Reserved. // // NOTICE: You are permitted to use, modify, and distribute this file // in accordance with the terms of the license agreement accompanying it. // ------------------------------------------------------------------------------ Object.defineProperty(exports, "__esModule", { value: true }); exports.EventCommandMap = void 0; var tslib_1 = require("tslib"); var inversify_1 = require("inversify"); var IEventDispatcher_1 = require("../../../events/api/IEventDispatcher"); var IContext_1 = require("../../../framework/api/IContext"); var CommandTriggerMap_1 = require("../../commandCenter/impl/CommandTriggerMap"); var EventCommandTrigger_1 = require("./EventCommandTrigger"); /** * @private */ var EventCommandMap = /** @class */ (function () { /*============================================================================*/ /* Constructor */ /*============================================================================*/ /** * @private */ function EventCommandMap(context, dispatcher) { /*============================================================================*/ /* Private Properties */ /*============================================================================*/ this._mappingProcessors = []; this._injector = context.injector; this._logger = context.getLogger(this); this._dispatcher = dispatcher; this._triggerMap = new CommandTriggerMap_1.CommandTriggerMap(this._getKey, this._createTrigger.bind(this)); } /*============================================================================*/ /* Public Functions */ /*============================================================================*/ /** * @inheritDoc */ EventCommandMap.prototype.map = function (type, eventClass) { return this._getTrigger(type, eventClass).createMapper(); }; /** * @inheritDoc */ EventCommandMap.prototype.unmap = function (type, eventClass) { return this._getTrigger(type, eventClass).createMapper(); }; /** * @inheritDoc */ EventCommandMap.prototype.addMappingProcessor = function (handler) { if (this._mappingProcessors.indexOf(handler) === -1) { this._mappingProcessors.push(handler); } return this; }; /*============================================================================*/ /* Private Functions */ /*============================================================================*/ EventCommandMap.prototype._getKey = function (type, eventClass) { return type + eventClass; }; EventCommandMap.prototype._getTrigger = function (type, eventClass) { return this._triggerMap.getTrigger(type, eventClass); }; EventCommandMap.prototype._createTrigger = function (type, eventClass) { return new EventCommandTrigger_1.EventCommandTrigger(this._injector, this._dispatcher, type, eventClass, this._mappingProcessors, this._logger); }; EventCommandMap = tslib_1.__decorate([ inversify_1.injectable(), tslib_1.__param(0, inversify_1.inject(IContext_1.IContext)), tslib_1.__param(1, inversify_1.inject(IEventDispatcher_1.IEventDispatcher)), tslib_1.__metadata("design:paramtypes", [Object, Object]) ], EventCommandMap); return EventCommandMap; }()); exports.EventCommandMap = EventCommandMap; //# sourceMappingURL=EventCommandMap.js.map