class EventsBus { events : { [ key ] : Array < Function > ; } ; constructor ( ) { this . events = { } ; } on ( eventName , callBack ) { if ( ! this . events [ eventName ] ) { this . events [ eventName ] = [ ] ; } this . events [ eventName ] . push ( callBack ) ; } emit ( eventName ) { const event = this . events [ eventName ] ; if ( ! event ) return ; Object . values ( event ) . forEach ( ( callback ) => callback ( ) ) ; } } const eventsBus = new EventsBus ( ) ; export default eventsBus ;