| 1 | import type { IDisposable, IEvent } from './interfaces'; |
| 2 | |
| 3 | export class EventEmitter<T> { |
| 4 | private listeners: Array<(arg: T) => void> = []; |
| 5 | |
| 6 | fire(arg: T): void { |
| 7 | for (const listener of this.listeners) { |
| 8 | listener(arg); |
| 9 | } |
| 10 | } |
| 11 | |
| 12 | event: IEvent<T> = (listener) => { |
| 13 | this.listeners.push(listener); |
| 14 | return { |
| 15 | dispose: () => { |
| 16 | const index = this.listeners.indexOf(listener); |
| 17 | if (index >= 0) { |
| 18 | this.listeners.splice(index, 1); |
| 19 | } |
| 20 | }, |
| 21 | }; |
| 22 | }; |
| 23 | |
| 24 | dispose(): void { |
| 25 | this.listeners = []; |
| 26 | } |
| 27 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…