module version typedef { Events } Events property export default class Events { type { { } } private subscribers : { [ name ] : Array < ( data ? : any ) => any > ; } = { } ; param { String } eventName param { Function } callback public on ( eventName , callback ) { if ( ! ( eventName in this . subscribers ) ) { this . subscribers [ eventName ] = [ ] ; } this . subscribers [ eventName ] . push ( callback ) ; } param { String } eventName param { Object } data public emit ( eventName , data ? ) { if ( ! this . subscribers [ eventName ] ) { return ; } this . subscribers [ eventName ] . reduce ( ( previousData , currentHandler ) => { const newData = currentHandler ( previousData ) ; return newData ? newData : previousData ; } , data ) ; } param eventName param callback public off ( eventName , callback ) { for ( let i = 0 ; i < this . subscribers [ eventName ] . length ; i ++ ) { if ( this . subscribers [ eventName ] [ i ] === callback ) { delete this . subscribers [ eventName ] [ i ] ; break ; } } } /**
     * Destroyer
     * clears subsribers list
     */ public destroy ( ) { this . subscribers = null ; } }