import { EventEmitter } from 'events' ; import { logger } from 'yanl' ; type ListenersMap = { [ event ] : ( ... args : any [ ] ) => void ; } ; export class SimpleEventEmitter < Listeners extends ListenersMap = ListenersMap > { private emitter = new EventEmitter ( ) ; public on < E extends keyof Listeners > ( event , listener ) { this . emitter . addListener ( event , listener ) ; return this ; } public off < E extends keyof Listeners > ( event , listener ) { logger . debug ( 'removed all listeners' , event ) ; this . emitter . removeListener ( event , listener ) ; return this ; } public removeAllListeners ( event ? ) { this . emitter . removeAllListeners ( event ) ; return this ; } protected emit < E extends keyof Listeners > ( event , ... args ) { logger . debug ( 'emitted event' , event , ... args ) ; return this . emitter . emit ( event , ... args ) ; } }