| 123456789101112131415161718192021222324 |
- class EventBus {
- emits: Map<string, Function> = new Map<string, Function>();
- on(name: string, callback: Function) {
- this.emits.set(name, callback);
- };
- off(name: string) {
- this.emits.delete(name);
- };
- exists(name: string) {
- return this.emits.has(name);
- }
- emit(name: string, ...arg: any[]) {
- if (this.emits.has(name)) {
- let cb = this.emits.get(name)
- return cb!(...arg)
- }
- };
- }
- export default EventBus
|