export class EventEmitter { events_ : { [ evtName ] : Array < Function > ; } = { } ; on ( event , cb ) { this . events_ = this . events_ || { } ; this . events_ [ event ] = this . events_ [ event ] || [ ] ; this . events_ [ event ] . push ( cb ) ; } off ( event , cb ) { this . events_ = this . events_ || { } ; if ( event in this . events_ === false ) return ; this . events_ [ event ] . splice ( this . events_ [ event ] . indexOf ( cb ) , 1 ) ; } trigger ( event , ... args ) { this . events_ = this . events_ || { } ; if ( event in this . events_ === false ) return ; for ( var i = 0 ; i < this . events_ [ event ] . length ; i ++ ) { this . events_ [ event ] [ i ] . apply ( this , Array . prototype . slice . call ( arguments , 1 ) ) ; } } } export class ArrayEmitter < T > extends EventEmitter { array : T [ ] = [ ] ; push ( ... items ) { const rVal = this . array . push ( ... items ) ; this . trigger ( 'change' ) ; return rVal ; } empty ( ) { this . array . length = 0 ; this . trigger ( 'change' ) ; } remove ( item ) { const index = this . array . indexOf ( item ) ; if ( index > - 1 ) { this . array . splice ( index , 1 ) ; this . trigger ( 'change' ) ; return true ; } return false ; } }