UNPKG

@visactor/vrender-core

Version:

```typescript import { xxx } from '@visactor/vrender-core'; ```

54 lines (51 loc) 2.53 kB
import { PluginRegistry } from "../registry"; const EMPTY_AUTO_ENABLE_PROVIDER = { getContributions: () => [] }; export 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 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(); } } //# sourceMappingURL=plugin-service.js.map