@robotlegsjs/createjs
Version:
CreateJS View Integration with RobotlegsJS
86 lines • 3.86 kB
JavaScript
"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.MediatorMapper = void 0;
var MediatorMapping_1 = require("./MediatorMapping");
/**
* @private
*/
var MediatorMapper = /** @class */ (function () {
/*============================================================================*/
/* Constructor */
/*============================================================================*/
/**
* @private
*/
function MediatorMapper(typeFilter, handler, logger) {
/*============================================================================*/
/* Private Properties */
/*============================================================================*/
this._mappings = new Map();
this._typeFilter = typeFilter;
this._handler = handler;
this._logger = logger;
}
/*============================================================================*/
/* Public Functions */
/*============================================================================*/
/**
* @inheritDoc
*/
MediatorMapper.prototype.toMediator = function (mediatorClass) {
var mapping = this._mappings.get(mediatorClass);
return mapping ? this._overwriteMapping(mapping) : this._createMapping(mediatorClass);
};
/**
* @inheritDoc
*/
MediatorMapper.prototype.fromMediator = function (mediatorClass) {
var mapping = this._mappings.get(mediatorClass);
if (mapping) {
this._deleteMapping(mapping);
}
};
/**
* @inheritDoc
*/
MediatorMapper.prototype.fromAll = function () {
this._mappings.forEach(this._deleteMapping, this);
};
/*============================================================================*/
/* Private Functions */
/*============================================================================*/
MediatorMapper.prototype._createMapping = function (mediatorClass) {
var mapping = new MediatorMapping_1.MediatorMapping(this._typeFilter, mediatorClass);
this._handler.addMapping(mapping);
this._mappings.set(mediatorClass, mapping);
if (this._logger) {
this._logger.debug("{0} mapped to {1}", [this._typeFilter, mapping]);
}
return mapping;
};
MediatorMapper.prototype._deleteMapping = function (mapping) {
this._handler.removeMapping(mapping);
this._mappings.delete(mapping.mediatorClass);
if (this._logger) {
this._logger.debug("{0} unmapped from {1}", [this._typeFilter, mapping]);
}
};
MediatorMapper.prototype._overwriteMapping = function (mapping) {
if (this._logger) {
this._logger.warn("{0} already mapped to {1}\n" +
'If you have overridden this mapping intentionally you can use "unmap()" ' +
"prior to your replacement mapping in order to avoid seeing this message.\n", [this._typeFilter, mapping]);
}
this._deleteMapping(mapping);
return this._createMapping(mapping.mediatorClass);
};
return MediatorMapper;
}());
exports.MediatorMapper = MediatorMapper;
//# sourceMappingURL=MediatorMapper.js.map