diff --git a/packages/editor/src/services/BaseService.ts b/packages/editor/src/services/BaseService.ts index 20bd6805..15dd67a4 100644 --- a/packages/editor/src/services/BaseService.ts +++ b/packages/editor/src/services/BaseService.ts @@ -199,24 +199,33 @@ export default class extends EventEmitter { * @deprecated 请使用usePlugin代替 */ public use(options: Record) { - Object.entries(options).forEach(([methodName, method]: [string, Function]) => { + for (const [methodName, method] of Object.entries(options)) { if (typeof method === 'function') this.middleware[methodName].push(method); - }); + } } public usePlugin(options: Record) { - Object.entries(options).forEach(([methodName, method]: [string, Function]) => { + for (const [methodName, method] of Object.entries(options)) { if (typeof method === 'function') this.pluginOptionsList[methodName].push(method); - }); + } + } + + public removePlugin(options: Record) { + for (const [methodName, method] of Object.entries(options)) { + if (Array.isArray(this.pluginOptionsList[methodName])) { + this.pluginOptionsList[methodName] = this.pluginOptionsList[methodName].filter((item) => item !== method); + } + } } public removeAllPlugins() { - Object.keys(this.pluginOptionsList).forEach((key) => { + for (const key of Object.keys(this.pluginOptionsList)) { this.pluginOptionsList[key] = []; - }); - Object.keys(this.middleware).forEach((key) => { + } + + for (const key of Object.keys(this.middleware)) { this.middleware[key] = []; - }); + } } private async doTask() {