export class DefaultEventEmitter { listeners : any = { } ; emit ( type , ... args ) { if ( ! ( type in this . listeners ) ) { return ; } const stack = this . listeners [ type ] ; for ( let i = 0 , l = stack . length ; i < l ; i ++ ) { stack [ i ] . call ( this , event ) ; const func = stack [ i ] ; if ( typeof func === 'function' ) { func ( ... args ) ; } } } addListener ( type , callback ) { if ( ! ( type in this . listeners ) ) { this . listeners [ type ] = [ ] ; } this . listeners [ type ] . push ( callback ) ; } removeListener ( type , callback ) { if ( ! ( type in this . listeners ) ) { return ; } const stack = this . listeners [ type ] ; for ( let i = 0 , l = stack . length ; i < l ; i ++ ) { if ( stack [ i ] === callback ) { stack . splice ( i , 1 ) ; return this . removeListener ( type , callback ) ; } } } }