export type EventHandler < T > = ( options : T ) => void ; export class Event < EventOptions extends Object > { eventHandlers : { [ handlerName ] : EventHandler < EventOptions > ; } = { } as any ; name : string ; param handlerName param handler addEventHandler ( handlerName , handler ) { if ( ! Object . keys ( this . eventHandlers ) . includes ( handlerName ) ) { this . eventHandlers [ handlerName ] = handler ; } } param handlerName removeEventHandler ( handlerName ) { if ( Object . keys ( this . eventHandlers ) . includes ( handlerName ) ) { delete this . eventHandlers [ handlerName ] ; } } param options fire ( options ) { for ( let handlerName in this . eventHandlers ) { this . eventHandlers [ handlerName ] ( options ) ; } } param name constructor ( name ) { this . name = name ; } }