export class EventDispatcher { readonly name : string ; private callbacks : Function [ ] = [ ] ; constructor ( name ) { this . name = name ; } register ( callback ) { if ( this . callbacks . indexOf ( callback ) >= 0 ) { return ; } this . callbacks . push ( callback ) ; } unregister ( callback ) { const i = this . callbacks . indexOf ( callback ) ; if ( i < 0 ) { throw new Error ( "Unknown callback." ) ; } this . callbacks . splice ( i , 1 ) ; } dispatch ( target ? ) { this . callbacks . forEach ( callback => { callback ( target ) ; } ) ; } }