all files / src/widgets/ widgetPluginFactory.ts

54.55% Statements 12/22
0% Branches 0/4
40% Functions 2/5
54.55% Lines 12/22
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36                                               
/* 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;