1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- 'use strict';
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: Dashboard
- *| (C) Copyright IBM Corp. 2019
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define(['../../lib/@waca/core-client/js/core-client/utils/ClassFactory'], function (ClassFactory) {
- var BoardModuleFactory = function () {
- function BoardModuleFactory(props) {
- _classCallCheck(this, BoardModuleFactory);
- this.modules = props.modules || [];
- this._cache = props.cache || {};
- this._loader = props.loader || ClassFactory;
- this.logger = props.logger;
- }
- BoardModuleFactory.prototype.make = function make(type) {
- var _this = this;
- var module = this.getModuleByType(type);
- if (!module) {
- throw new Error('Module with type "' + type + '" not found');
- }
- var promise;
- if (this.isCached(module)) {
- promise = Promise.resolve(this.getFromCache(module));
- } else {
- promise = this.loadModule(module).then(function (ModuleClass) {
- _this.setToCache(module, ModuleClass);
- return ModuleClass;
- });
- }
- return promise.then(function (ModuleClass) {
- return new ModuleClass({
- logger: _this.logger
- });
- });
- };
- BoardModuleFactory.prototype.loadModule = function loadModule(module) {
- var _this2 = this;
- return this._loader.loadModule(module.path).catch(function (error) {
- _this2.logger.warn('[BoardModuleFactory]: attempted to load module "' + module.path + ' and failed"', error);
- throw error;
- });
- };
- BoardModuleFactory.prototype.getModuleByType = function getModuleByType(type) {
- var found;
- // TODO: update to find when everything is babelified
- for (var key in this.modules) {
- if (this.modules.hasOwnProperty(key) && this.modules[key].type === type) {
- found = this.modules[key];
- }
- }
- return found;
- };
- BoardModuleFactory.prototype.getDefaultModuleType = function getDefaultModuleType() {
- return BoardModuleFactory.defaultModuleType;
- };
- /* cache methods */
- BoardModuleFactory.prototype.isCached = function isCached(module) {
- return !!this._cache[module.type];
- };
- BoardModuleFactory.prototype.getFromCache = function getFromCache(module) {
- return this._cache[module.type];
- };
- BoardModuleFactory.prototype.setToCache = function setToCache(module, value) {
- this._cache[module.type] = value;
- return this;
- };
- return BoardModuleFactory;
- }();
- BoardModuleFactory.defaultModuleType = 'legacy';
- return BoardModuleFactory;
- });
- //# sourceMappingURL=BoardModuleFactory.js.map
|