@visactor/vrender-core
Version:
```typescript import { xxx } from '@visactor/vrender-core'; ```
60 lines (55 loc) • 2.7 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.DefaultPluginService = void 0;
const registry_1 = require("../registry"), EMPTY_AUTO_ENABLE_PROVIDER = {
getContributions: () => []
};
class DefaultPluginService {
constructor(autoEnablePlugins = EMPTY_AUTO_ENABLE_PROVIDER, deps = {}) {
var _a;
this.autoEnablePlugins = autoEnablePlugins, this.onStartupFinishedPlugin = [], this.onRegisterPlugin = [],
this.actived = !1, this.pluginRegistry = null !== (_a = deps.pluginRegistry) && void 0 !== _a ? _a : new registry_1.PluginRegistry;
}
active(stage, params) {
this.stage = stage, this.actived = !0;
const {pluginList: pluginList} = params;
(null == pluginList ? void 0 : pluginList.length) && this.autoEnablePlugins.getContributions().forEach((p => {
pluginList.includes(p.name) && this.install(p);
}));
}
findPluginsByName(name) {
const arr = [];
return this.onStartupFinishedPlugin.forEach((plugin => {
plugin.name === name && arr.push(plugin);
})), this.onRegisterPlugin.forEach((plugin => {
plugin.name === name && arr.push(plugin);
})), arr;
}
install(plugin) {
this.register(plugin);
}
uninstall(name) {
this.findPluginsByName(name).forEach((plugin => {
this.unRegister(plugin);
})), this.pluginRegistry.uninstall(name);
}
register(plugin) {
this.pluginRegistry.install(plugin), "onStartupFinished" === plugin.activeEvent ? this.onStartupFinishedPlugin.includes(plugin) || this.onStartupFinishedPlugin.push(plugin) : "onRegister" === plugin.activeEvent && (this.onRegisterPlugin.includes(plugin) || (this.onRegisterPlugin.push(plugin),
plugin.activate(this)));
}
unRegister(plugin) {
"onStartupFinished" === plugin.activeEvent ? this.onStartupFinishedPlugin = this.onStartupFinishedPlugin.filter((item => item !== plugin)) : "onRegister" === plugin.activeEvent && (this.onRegisterPlugin = this.onRegisterPlugin.filter((item => item !== plugin))),
this.pluginRegistry.get(plugin.name) === plugin && this.pluginRegistry.uninstall(plugin.name),
plugin.deactivate(this);
}
release(...params) {
this.onStartupFinishedPlugin.forEach((plugin => {
plugin.deactivate(this);
})), this.onStartupFinishedPlugin = [], this.onRegisterPlugin.forEach((plugin => {
plugin.deactivate(this);
})), this.onRegisterPlugin = [], this.pluginRegistry.clear();
}
}
exports.DefaultPluginService = DefaultPluginService;
//# sourceMappingURL=plugin-service.js.map