UNPKG

@robotlegsjs/createjs

Version:
58 lines 2.88 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.ContextViewExtension = void 0; var core_1 = require("@robotlegsjs/core"); var IContextView_1 = require("./api/IContextView"); var createjs_patch_1 = require("./createjsPatch/createjs-patch"); var ContextView_1 = require("./impl/ContextView"); /** * <p>This Extension waits for a ContextView to be added as a configuration * and maps it into the context's injector.</p> * * <p>It should be installed before context initialization.</p> */ var ContextViewExtension = /** @class */ (function () { function ContextViewExtension() { } /*============================================================================*/ /* Public Functions */ /*============================================================================*/ /** * @inheritDoc */ ContextViewExtension.prototype.extend = function (context) { this._injector = context.injector; this._logger = context.getLogger(this); context.beforeInitializing(this._beforeInitializing.bind(this)); context.addConfigHandler(core_1.instanceOfType(ContextView_1.ContextView), this._handleContextView.bind(this)); }; /*============================================================================*/ /* Private Functions */ /*============================================================================*/ ContextViewExtension.prototype._handleContextView = function (contextView) { if (this._injector.isBound(IContextView_1.IContextView)) { this._logger.warn("A contextView has already been installed, ignoring {0}", [ contextView.view ]); } else { this._logger.debug("Mapping {0} as contextView", [contextView.view]); createjs_patch_1.applyCreateJSPatch(contextView.view); this._injector.bind(IContextView_1.IContextView).toConstantValue(contextView); } }; ContextViewExtension.prototype._beforeInitializing = function () { if (!this._injector.isBound(IContextView_1.IContextView)) { this._logger.error("A ContextView must be installed if you install the ContextViewExtension."); } }; return ContextViewExtension; }()); exports.ContextViewExtension = ContextViewExtension; //# sourceMappingURL=ContextViewExtension.js.map