MCPcopy Create free account
hub / github.com/Fiddle-Digital/string-scroll / EventManager

Class EventManager

src/EventManager.ts:1–25  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1export 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected