| 671 | } |
| 672 | |
| 673 | export 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 |
nothing calls this directly
no outgoing calls
no test coverage detected