| 1 | export class EventManager{ |
| 2 | private events: Map<string, Array<Function>> = new Map<string, Array<Function>>() |
| 3 | on(id: string, event: Function){ |
| 4 | if ( this.events.has(id) == false) { |
| 5 | this.events.set(id, []) |
| 6 | } |
| 7 | this.events.get(id)?.push(event) |
| 8 | } |
| 9 | public has(id: string) { |
| 10 | return this.events.has(id) |
| 11 | } |
| 12 | public emit(id: string, value: any) { |
| 13 | if (this.events.has(id)) { |
| 14 | this.events.get(id)?.forEach((event: any) => { |
| 15 | event(value) |
| 16 | }); |
| 17 | } |
| 18 | } |
| 19 | public off(id: string, event: Function) { |
| 20 | let ea = this.events.get(id) |
| 21 | if (ea!=null) { |
| 22 | this.events.set(id, ea.filter((h: any) => h !== event)) |
| 23 | } |
| 24 | } |
| 25 | } |
nothing calls this directly
no outgoing calls
no test coverage detected