import { Emittable } from './emittable.interface' ; import { Subscribable } from './subscribable.interface' ; import { Subscriber } from './subscriber.interface' ; import { Subscription } from './subscription.interface' ; export class EventEmitter < EventType > implements Emittable < EventType > , Subscribable < EventType > { private subscribers = new Set < Subscriber < EventType > > ( ) ; public subscribe ( handleEvent ) { const subscriber = { handleEvent } ; this . subscribers . add ( subscriber ) ; return { unsubscribe : ( ) => this . subscribers . delete ( subscriber ) , } ; } public emit ( event ) { this . subscribers . forEach ( subscriber => subscriber . handleEvent ( event ) ) ; } }