import { injectable , inject } from "inversify" ; import { IContext } from "../../../framework/api/IContext" ; import { IInjector } from "../../../framework/api/IInjector" ; import { ILogger } from "../../../framework/api/ILogger" ; import { IEvent } from "../../../events/api/IEvent" ; import { IEventDispatcher } from "../../../events/api/IEventDispatcher" ; import { IClass } from "../../matching/IClass" ; import { ICommandMapper } from "../../commandCenter/dsl/ICommandMapper" ; import { ICommandUnmapper } from "../../commandCenter/dsl/ICommandUnmapper" ; import { CommandTriggerMap } from "../../commandCenter/impl/CommandTriggerMap" ; import { IEventCommandMap } from "../../eventCommandMap/api/IEventCommandMap" ; import { EventCommandTrigger } from "./EventCommandTrigger" ; private @ injectable ( ) export class EventCommandMap implements IEventCommandMap { private _mappingProcessors : any [ ] = [ ] ; private _injector : IInjector ; private _dispatcher : IEventDispatcher ; private _triggerMap : CommandTriggerMap ; private _logger : ILogger ; private constructor ( @ inject ( IContext ) context , @ inject ( IEventDispatcher ) dispatcher ) { this . _injector = context . injector ; this . _logger = context . getLogger ( this ) ; this . _dispatcher = dispatcher ; this . _triggerMap = new CommandTriggerMap ( this . getKey , this . createTrigger . bind ( this ) ) ; } inheritDoc public map ( type , eventClass ? ) { return this . getTrigger ( type , eventClass ) . createMapper ( ) ; } inheritDoc public unmap ( type , eventClass ? ) { return this . getTrigger ( type , eventClass ) . createMapper ( ) ; } inheritDoc public addMappingProcessor ( handler ) { if ( this . _mappingProcessors . indexOf ( handler ) === - 1 ) { this . _mappingProcessors . push ( handler ) ; } return this ; } private getKey ( type , eventClass ) { return type + eventClass ; } private getTrigger ( type , eventClass ) { return < EventCommandTrigger > this . _triggerMap . getTrigger ( type , eventClass ) ; } private createTrigger ( type , eventClass ) { return new EventCommandTrigger ( this . _injector , this . _dispatcher , type , eventClass , this . _mappingProcessors , this . _logger ) ; } }