import { IEventEmitter , IEventListener , IEventListenerDisposer } from './interfaces' ; export class EventEmitter < TEvent > implements IEventEmitter < TEvent > { /**
     * Holds an array of listening functions
     */ protected listeners : IEventListener < TEvent > [ ] = [ ] ; /**
     * Emits an Event
     */ emit ( e ? ) { this . listeners . map ( listener => listener ( e ) ) ; } /**
     * Subscribes to the event, and return an event listener disposer
     */ subscribe ( listener ) { var isSubscribed = true ; this . listeners . push ( listener ) ; return ( ) => { if ( ! isSubscribed ) return ; isSubscribed = false ; const index = this . listeners . indexOf ( listener ) ; this . listeners . splice ( index , 1 ) ; } ; } /**
     * Disposes the EventEmitter
     */ dispose ( ) { this . listeners = [ ] ; } }