MCPcopy Create free account
hub / github.com/sqlchat/sqlchat / EventEmitter

Class EventEmitter

src/utils/event-emitter.ts:5–31  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3type Callback = () => void;
4
5class EventEmitter {
6 private static instance: EventEmitter;
7 private events: { [eventName: string]: Callback[] } = {};
8
9 private constructor() {}
10
11 public static getInstance(): EventEmitter {
12 if (!EventEmitter.instance) {
13 EventEmitter.instance = new EventEmitter();
14 }
15 return EventEmitter.instance;
16 }
17
18 on(eventName: EventType, callback: Callback) {
19 if (!this.events[eventName]) {
20 this.events[eventName] = [];
21 }
22 this.events[eventName].push(callback);
23 }
24
25 emit(eventName: EventType) {
26 const callbacks = this.events[eventName];
27 if (callbacks) {
28 callbacks.forEach((callback) => callback());
29 }
30 }
31}
32
33const getEventEmitter = () => {
34 return EventEmitter.getInstance();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected