@robotlegsjs/createjs
Version:
CreateJS View Integration with RobotlegsJS
102 lines • 4.15 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.MediatorViewHandler = void 0;
/**
* @private
*/
var MediatorViewHandler = /** @class */ (function () {
/*============================================================================*/
/* Constructor */
/*============================================================================*/
/**
* @private
*/
function MediatorViewHandler(factory) {
/*============================================================================*/
/* Private Properties */
/*============================================================================*/
this._mappings = [];
this._knownMappings = new Map();
this._factory = factory;
}
/*============================================================================*/
/* Public Functions */
/*============================================================================*/
/**
* @private
*/
MediatorViewHandler.prototype.addMapping = function (mapping) {
var index = this._mappings.indexOf(mapping);
if (index > -1) {
return;
}
this._mappings.push(mapping);
this._knownMappings.clear();
};
/**
* @private
*/
MediatorViewHandler.prototype.removeMapping = function (mapping) {
var index = this._mappings.indexOf(mapping);
if (index === -1) {
return;
}
this._mappings.splice(index, 1);
this._knownMappings.clear();
};
/**
* @private
*/
MediatorViewHandler.prototype.handleView = function (view, type) {
var interestedMappings = this._getInterestedMappingsFor(view, type);
if (interestedMappings) {
this._factory.createMediators(view, type, interestedMappings);
}
};
/**
* @private
*/
MediatorViewHandler.prototype.handleItem = function (item, type) {
var interestedMappings = this._getInterestedMappingsFor(item, type);
if (interestedMappings) {
this._factory.createMediators(item, type, interestedMappings);
}
};
/*============================================================================*/
/* Private Functions */
/*============================================================================*/
MediatorViewHandler.prototype._getInterestedMappingsFor = function (item, type) {
var _this = this;
// we've seen this type before and nobody was interested
if (this._knownMappings.get(type) === false) {
return null;
}
// we haven't seen this type before
if (this._knownMappings.get(type) === undefined) {
this._knownMappings.set(type, false);
this._mappings.forEach(function (mapping) {
if (mapping.matcher.matches(item)) {
if (!_this._knownMappings.get(type)) {
_this._knownMappings.set(type, []);
}
_this._knownMappings.get(type).push(mapping);
}
});
// nobody cares, let's get out of here
if (this._knownMappings.get(type) === false) {
return null;
}
}
// these mappings really do care
return this._knownMappings.get(type);
};
return MediatorViewHandler;
}());
exports.MediatorViewHandler = MediatorViewHandler;
//# sourceMappingURL=MediatorViewHandler.js.map