@robotlegsjs/createjs
Version:
CreateJS View Integration with RobotlegsJS
108 lines • 4.29 kB
JavaScript
;
// ------------------------------------------------------------------------------
// 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.MediatorMap = void 0;
var tslib_1 = require("tslib");
var core_1 = require("@robotlegsjs/core");
var MediatorFactory_1 = require("./MediatorFactory");
var MediatorMapper_1 = require("./MediatorMapper");
var MediatorViewHandler_1 = require("./MediatorViewHandler");
var NullMediatorUnmapper_1 = require("./NullMediatorUnmapper");
/**
* @private
*/
var MediatorMap = /** @class */ (function () {
/*============================================================================*/
/* Constructor */
/*============================================================================*/
/**
* @private
*/
function MediatorMap(context) {
/*============================================================================*/
/* Private Properties */
/*============================================================================*/
this._mappers = new Map();
this._NULL_UNMAPPER = new NullMediatorUnmapper_1.NullMediatorUnmapper();
this._logger = context.getLogger(this);
this._factory = new MediatorFactory_1.MediatorFactory(context.injector);
this._viewHandler = new MediatorViewHandler_1.MediatorViewHandler(this._factory);
}
/*============================================================================*/
/* Public Functions */
/*============================================================================*/
/**
* @inheritDoc
*/
MediatorMap.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
*/
MediatorMap.prototype.map = function (type) {
return this.mapMatcher(new core_1.TypeMatcher().allOf(type));
};
/**
* @inheritDoc
*/
MediatorMap.prototype.unmapMatcher = function (matcher) {
return this._mappers.get(matcher.createTypeFilter().descriptor) || this._NULL_UNMAPPER;
};
/**
* @inheritDoc
*/
MediatorMap.prototype.unmap = function (type) {
return this.unmapMatcher(new core_1.TypeMatcher().allOf(type));
};
/**
* @inheritDoc
*/
MediatorMap.prototype.handleView = function (view, type) {
this._viewHandler.handleView(view, type);
};
/**
* @inheritDoc
*/
MediatorMap.prototype.mediate = function (item) {
this._viewHandler.handleItem(item, item.constructor);
};
/**
* @inheritDoc
*/
MediatorMap.prototype.unmediate = function (item) {
this._factory.removeMediators(item);
};
/**
* @inheritDoc
*/
MediatorMap.prototype.unmediateAll = function () {
this._factory.removeAllMediators();
};
/*============================================================================*/
/* Private Functions */
/*============================================================================*/
MediatorMap.prototype._createMapper = function (matcher) {
return new MediatorMapper_1.MediatorMapper(matcher.createTypeFilter(), this._viewHandler, this._logger);
};
MediatorMap = tslib_1.__decorate([
core_1.injectable(),
tslib_1.__param(0, core_1.inject(core_1.IContext)),
tslib_1.__metadata("design:paramtypes", [Object])
], MediatorMap);
return MediatorMap;
}());
exports.MediatorMap = MediatorMap;
//# sourceMappingURL=MediatorMap.js.map