enso/app/gui2/shared/events.ts
somebody1234 44f2f425c0
[gui2] Language Server binary protocol, and loading of visualization data (#7873)
- Depends on #7773.

- Implements binary WebSocket protocol (data protocol)
- Performs some editor initialization (the bare minimum so that visualizations work)
- Adds event handlers to receive visualization data updates

# Important Notes
None
2023-10-07 20:57:47 +00:00

26 lines
485 B
TypeScript

import { ObservableV2 } from 'lib0/observable'
type EventHandler = (...arg0: any[]) => void
type EventMap = {
[key: string]: EventHandler
}
export class EventEmitter extends ObservableV2<EventMap> {
emit(name: string, ...args: unknown[]): void {
super.emit(name, args)
}
addListener(name: string, f: EventHandler) {
this.on(name, f)
}
removeListener(name: string, f: EventHandler) {
this.off(name, f)
}
removeAllListeners() {
this.destroy()
}
}