MCPcopy
hub / github.com/foambubble/foam / EventEmitter

Class EventEmitter

packages/foam-vscode/src/test/vscode-mock.ts:673–704  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

671}
672
673export class EventEmitter<T> {
674 private listeners: ((e: T) => any)[] = [];
675
676 get event(): Event<T> {
677 return (listener: (e: T) => any, thisArg?: any) => {
678 const boundListener = thisArg ? listener.bind(thisArg) : listener;
679 this.listeners.push(boundListener);
680 return {
681 dispose: () => {
682 const index = this.listeners.indexOf(boundListener);
683 if (index >= 0) {
684 this.listeners.splice(index, 1);
685 }
686 },
687 };
688 };
689 }
690
691 fire(data: T): void {
692 this.listeners.forEach(listener => {
693 try {
694 listener(data);
695 } catch (error) {
696 console.error('Error in event listener:', error);
697 }
698 });
699 }
700
701 dispose(): void {
702 this.listeners = [];
703 }
704}
705
706// ===== Diagnostics =====
707

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected