/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
var widgetPluginInstance_1 = require("./widgetPluginInstance");
var WidgetPluginFactory = (function () {
function WidgetPluginFactory(type, store) {
this.type = type;
this.store = store;
// TODO: The WidgetPluginInstance should be a plain class that might have access to the underlying component
this.instances = {};
this.disposed = false;
}
WidgetPluginFactory.prototype.getInstance = function (id) {
if (this.disposed === true) {
throw new Error("Try to create widget of destroyed type: " + this.type);
}
if (this.instances[id]) {
return this.instances[id];
}
this.instances[id] = new widgetPluginInstance_1.WidgetPluginInstance(id, this.store);
return this.instances[id];
};
WidgetPluginFactory.prototype.dispose = function () {
this.disposed = true;
_.valuesIn(this.instances).forEach(function (widgetPluginInstance) {
widgetPluginInstance.dispose();
});
this.instances = {};
};
return WidgetPluginFactory;
}());
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = WidgetPluginFactory;
|