export type EventHandler < T > = ( arg : T ) => void ; export class EventDelegate < T > { private handlers : EventHandler < T > [ ] = [ ] ; public add ( handler ) { this . handlers . push ( handler ) ; return handler ; } public remove ( handler ) { this . handlers = this . handlers . filter ( ( h ) => h !== handler ) ; } public trigger ( input ) { for ( const h of this . handlers ) { h ( input ) ; } } }