From 8d6da3712efdc269cbaa47b003bf667bbce00ae7 Mon Sep 17 00:00:00 2001 From: roymondchen Date: Thu, 26 Jun 2025 16:49:32 +0800 Subject: [PATCH] =?UTF-8?q?feat(editor):=20service=E6=96=B0=E5=A2=9Eremove?= =?UTF-8?q?Plugin=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/editor/src/services/BaseService.ts | 25 ++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) 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() {