mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-10-29 16:05:34 +00:00
27 lines
548 B
Go
27 lines
548 B
Go
class Bus {
|
|
list: { [key: string]: Array<Function> };
|
|
constructor() {
|
|
this.list = {};
|
|
}
|
|
|
|
on(name: string, fn: Function) {
|
|
this.list[name] = this.list[name] || [];
|
|
this.list[name].push(fn);
|
|
}
|
|
|
|
emit(name: string, data?: any) {
|
|
if (this.list[name]) {
|
|
this.list[name].forEach((fn: Function) => {
|
|
fn(data);
|
|
});
|
|
}
|
|
}
|
|
|
|
off(name: string) {
|
|
if (this.list[name]) {
|
|
delete this.list[name];
|
|
}
|
|
}
|
|
}
|
|
export default Bus;
|