all files / src/pluginApi/ pluginRegistry.ts

85.29% Statements 29/34
50% Branches 4/8
80% Functions 8/10
85.29% Lines 29/34
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59        13× 13× 13×                                         26×     26×        
/* 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 _ = require("lodash");
var PluginRegistry = (function () {
    function PluginRegistry(_store) {
        this._store = _store;
        this._plugins = {};
        Iif (!_store) {
            throw new Error("PluginRegistry must be initialized with a Store");
        }
    }
    Object.defineProperty(PluginRegistry.prototype, "store", {
        get: function () {
            return this._store;
        },
        enumerable: true,
        configurable: true
    });
    PluginRegistry.prototype.register = function (module) {
        Iif (!this._store === undefined) {
            throw new Error("PluginRegistry has no store. Set the store property before registering modules!");
        }
        console.assert(module.TYPE_INFO !== undefined, "Missing TYPE_INFO on plugin module. Every module must export TYPE_INFO");
        console.assert(module.TYPE_INFO.type !== undefined, "Missing TYPE_INFO.type on plugin TYPE_INFO.");
        this._plugins[module.TYPE_INFO.type] = this.createPluginFromModule(module);
    };
    PluginRegistry.prototype.createPluginFromModule = function (module) {
        throw new Error("PluginRegistry must implement createPluginFromModule");
    };
    PluginRegistry.prototype.hasPlugin = function (type) {
        return this._plugins[type] !== undefined;
    };
    // TODO: rename to getPluginFactory() when also widgets are in TypeScript?
    PluginRegistry.prototype.getPlugin = function (type) {
        var plugin = this._plugins[type];
        Iif (!plugin) {
            throw new Error("Can not find plugin with type '" + type + "' in plugin registry.");
        }
        return plugin;
    };
    PluginRegistry.prototype.getPlugins = function () {
        return _.assign({}, this._plugins);
    };
    PluginRegistry.prototype.dispose = function () {
        _.valuesIn(this._plugins).forEach(function (plugin) {
            Eif (_.isFunction(plugin.dispose)) {
                plugin.dispose();
            }
        });
        this._plugins = {};
    };
    return PluginRegistry;
}());
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = PluginRegistry;