/* 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;
|