UNPKG

@robotlegsjs/phaser

Version:

RobotlegsJS integration with Phaser Scene Manager

108 lines 4.38 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.ViewMediatorMap = void 0; var tslib_1 = require("tslib"); var core_1 = require("@robotlegsjs/core"); var MediatorMapper_1 = require("./MediatorMapper"); var NullMediatorUnmapper_1 = require("./NullMediatorUnmapper"); var ViewMediatorFactory_1 = require("./ViewMediatorFactory"); var ViewMediatorHandler_1 = require("./ViewMediatorHandler"); /** * @private */ var ViewMediatorMap = /** @class */ (function () { /*============================================================================*/ /* Constructor */ /*============================================================================*/ /** * @private */ function ViewMediatorMap(context) { /*============================================================================*/ /* Private Properties */ /*============================================================================*/ this._mappers = new Map(); this._NULL_UNMAPPER = new NullMediatorUnmapper_1.NullMediatorUnmapper(); this._logger = context.getLogger(this); this._factory = new ViewMediatorFactory_1.ViewMediatorFactory(context.injector); this._viewHandler = new ViewMediatorHandler_1.ViewMediatorHandler(this._factory); } /*============================================================================*/ /* Public Functions */ /*============================================================================*/ /** * @inheritDoc */ ViewMediatorMap.prototype.mapMatcher = function (matcher) { var desc = matcher.createTypeFilter().descriptor; var mapper = this._mappers.get(desc); if (mapper) { return mapper; } mapper = this._createMapper(matcher); this._mappers.set(desc, mapper); return mapper; }; /** * @inheritDoc */ ViewMediatorMap.prototype.map = function (view) { return this.mapMatcher(new core_1.TypeMatcher().allOf(view)); }; /** * @inheritDoc */ ViewMediatorMap.prototype.unmapMatcher = function (matcher) { return this._mappers.get(matcher.createTypeFilter().descriptor) || this._NULL_UNMAPPER; }; /** * @inheritDoc */ ViewMediatorMap.prototype.unmap = function (view) { return this.unmapMatcher(new core_1.TypeMatcher().allOf(view)); }; /** * @inheritDoc */ ViewMediatorMap.prototype.handleView = function (view, type) { this._viewHandler.handleView(view, type); }; /** * @inheritDoc */ ViewMediatorMap.prototype.mediate = function (view) { this._viewHandler.handleItem(view, view.constructor); }; /** * @inheritDoc */ ViewMediatorMap.prototype.unmediate = function (view) { this._factory.removeMediators(view); }; /** * @inheritDoc */ ViewMediatorMap.prototype.unmediateAll = function () { this._factory.removeAllMediators(); }; /*============================================================================*/ /* Private Functions */ /*============================================================================*/ ViewMediatorMap.prototype._createMapper = function (matcher) { return new MediatorMapper_1.MediatorMapper(matcher.createTypeFilter(), this._viewHandler, this._logger); }; ViewMediatorMap = tslib_1.__decorate([ core_1.injectable(), tslib_1.__param(0, core_1.inject(core_1.IContext)), tslib_1.__metadata("design:paramtypes", [Object]) ], ViewMediatorMap); return ViewMediatorMap; }()); exports.ViewMediatorMap = ViewMediatorMap; //# sourceMappingURL=ViewMediatorMap.js.map