import { EventInterface , EventHandlerInterface , Class , BoosterConfig } from '@boostercloud/framework-types' ; import { Booster } from '../booster' ; export function EventHandler < TEvent extends EventInterface > ( event ) { return ( eventHandlerClass ) => registerEventHandler ( event . name , eventHandlerClass ) ; } function registerEventHandler < TEventHandler extends EventHandlerInterface > ( eventName , eventHandlerClass ) { Booster . configureCurrentEnv ( ( config ) : void => { const registeredEventHandlers = config . eventHandlers [ eventName ] || [ ] ; if ( registeredEventHandlers . some ( ( klass ) => klass == eventHandlerClass ) ) { return ; } registeredEventHandlers . push ( eventHandlerClass ) ; config . eventHandlers [ eventName ] = registeredEventHandlers ; } ) ; }