feat: update ms system
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { injectable } from "@ccms/container";
|
||||
import { injectable } from "@ccms/container"
|
||||
|
||||
export namespace channel {
|
||||
/**
|
||||
@@ -17,32 +17,32 @@ export namespace channel {
|
||||
* @param exec 执行器
|
||||
*/
|
||||
listen(plugin: any, channel: string, exec: ChannelListener) {
|
||||
if (!plugin || !plugin.description || !plugin.description.name) throw new TypeError('Plugin can\'t be undefiend!');
|
||||
let name = plugin.description.name;
|
||||
if (!plugin || !plugin.description || !plugin.description.name) throw new TypeError('Plugin can\'t be undefiend!')
|
||||
let name = plugin.description.name
|
||||
let listener = this.register(channel, exec)
|
||||
if (!this.listenerMap[name]) this.listenerMap[name] = [];
|
||||
if (!this.listenerMap[name]) this.listenerMap[name] = []
|
||||
let offExec = () => {
|
||||
this.unregister(channel, listener);
|
||||
console.debug(`[${name}] unregister channel ${channel}`);
|
||||
};
|
||||
this.unregister(channel, listener)
|
||||
console.debug(`[${name}] unregister channel ${channel}`)
|
||||
}
|
||||
var off = {
|
||||
channel,
|
||||
listener,
|
||||
off: offExec
|
||||
};
|
||||
this.listenerMap[name].push(off);
|
||||
console.debug(`[${name}] register channel ${channel} => ${exec.name || '[anonymous]'}`);
|
||||
return off;
|
||||
}
|
||||
this.listenerMap[name].push(off)
|
||||
console.debug(`[${name}] register channel ${channel} => ${exec.name || '[anonymous]'}`)
|
||||
return off
|
||||
}
|
||||
/**
|
||||
* 关闭插件注册的通道
|
||||
* @param plugin 插件
|
||||
*/
|
||||
disable(plugin: any) {
|
||||
var channelCache = this.listenerMap[plugin.description.name];
|
||||
var channelCache = this.listenerMap[plugin.description.name]
|
||||
if (channelCache) {
|
||||
channelCache.forEach(t => t.off());
|
||||
delete this.listenerMap[plugin.description.name];
|
||||
channelCache.forEach(t => t.off())
|
||||
delete this.listenerMap[plugin.description.name]
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user