mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-06-28 13:25:17 +08:00
feat(editor): service新增removePlugin方法
This commit is contained in:
parent
b78ef20602
commit
8d6da3712e
@ -199,24 +199,33 @@ export default class extends EventEmitter {
|
|||||||
* @deprecated 请使用usePlugin代替
|
* @deprecated 请使用usePlugin代替
|
||||||
*/
|
*/
|
||||||
public use(options: Record<string, Function>) {
|
public use(options: Record<string, Function>) {
|
||||||
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);
|
if (typeof method === 'function') this.middleware[methodName].push(method);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public usePlugin(options: Record<string, Function>) {
|
public usePlugin(options: Record<string, Function>) {
|
||||||
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);
|
if (typeof method === 'function') this.pluginOptionsList[methodName].push(method);
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public removePlugin(options: Record<string, Function>) {
|
||||||
|
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() {
|
public removeAllPlugins() {
|
||||||
Object.keys(this.pluginOptionsList).forEach((key) => {
|
for (const key of Object.keys(this.pluginOptionsList)) {
|
||||||
this.pluginOptionsList[key] = [];
|
this.pluginOptionsList[key] = [];
|
||||||
});
|
}
|
||||||
Object.keys(this.middleware).forEach((key) => {
|
|
||||||
|
for (const key of Object.keys(this.middleware)) {
|
||||||
this.middleware[key] = [];
|
this.middleware[key] = [];
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async doTask() {
|
private async doTask() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user