class Emitter { private listeners = { } ; on ( eventName , callback ) { const listeners = this . listeners [ eventName ] || [ ] ; listeners . push ( callback ) ; this . listeners [ eventName ] = listeners ; } emit ( eventName , ... args ) { const listeners = this . listeners [ eventName ] ; if ( ! Array . isArray ( listeners ) ) return ; listeners . forEach ( ( callback ) => { try { callback . apply ( this , args ) ; } catch ( e ) { console . error ( e ) ; } } ) ; } off ( eventName ) { if ( ! this . listeners [ eventName ] ) { return ; } this . listeners [ eventName ] = [ ] ; } } export const emitter = new Emitter ( ) ;