feat: update ms system

This commit is contained in:
2020-09-17 17:44:48 +08:00
parent 7d6f6124b1
commit 8eaf789bce
23 changed files with 636 additions and 327 deletions

View File

@@ -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]
}
}
/**