export abstract class Event { protected events = new Map < string , ( ( ... args ) => void ) [ ] > ( ) ; param event param callback protected register ( event , callback ) { if ( this . events . has ( event ) ) { this . events . get ( event ) . push ( callback ) ; return ; } this . events . set ( event , [ callback ] ) ; } param event param args protected trigger ( event , ... args ) { let callbacks = this . events . get ( event ) ; if ( ! callbacks || callbacks . length === 0 ) return ; callbacks . forEach ( callback => process . nextTick ( ( ) => callback . apply ( null , args ) ) ) ; } removeEvent ( event , callback ) { let observers = this . events . get ( event ) ; if ( ! observers || observers . length === 0 ) return ; observers . splice ( observers . indexOf ( callback ) , 1 ) ; } removeAllEvents ( event ? ) { if ( ! event ) { this . events . clear ( ) ; return ; } if ( ! this . events . has ( event ) ) return false ; let observers = this . events . get ( event ) ; return observers . splice ( 0 , observers . length ) . length > 0 ; } }