import { Event , EventHandler } from './event' ; interface IEventTypes { [ eventName ] : any ; } export class EventList < EventTypes extends IEventTypes > { events : { [ event in keyof EventTypes ] : Event < EventTypes [ event ] > ; } = { } as any ; constructor ( eventsList ) { for ( let eventName of eventsList ) { this . events [ eventName ] = new Event ( < string > eventName ) ; } } on < E extends keyof EventTypes > ( eventName , handlerName , handler ) { if ( Object . keys ( this . events ) . includes ( < string > eventName ) ) { this . events [ eventName ] . addEventHandler ( handlerName , handler ) ; } } off < E extends keyof EventTypes > ( eventName , handlerName ) { if ( Object . keys ( this . events ) . includes ( < string > eventName ) ) { this . events [ eventName ] . removeEventHandler ( handlerName ) ; } } fire < E extends keyof EventTypes > ( eventName , options ) { if ( Object . keys ( this . events ) . includes ( < string > eventName ) ) { this . events [ eventName ] . fire ( options ) ; } } }