MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / EventEmitter

Class EventEmitter

src/shared/events.ts:4–25  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2import { IAmDisposable } from "./interfaces";
3
4export class EventEmitter<T> implements IAmDisposable {
5 private emitter = new evt.EventEmitter();
6
7 public fire(x: T): void {
8 this.emitter.emit("thing", x);
9 }
10
11 public listen(listener: (e: T) => any, thisArgs?: any): IAmDisposable {
12 if (thisArgs)
13 listener = listener.bind(thisArgs);
14 this.emitter.on("thing", listener);
15 return {
16 dispose: () => { this.emitter.removeListener("thing", listener); },
17 };
18 }
19
20 public get event(): Event<T> { return this.listen.bind(this); }
21
22 public dispose() {
23 this.emitter.removeAllListeners();
24 }
25}
26
27export class EventsEmitter<T> implements IAmDisposable {
28 private emitter = new evt.EventEmitter();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected