Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Event Command Map


An Event Command Map executes commands in response to events on a given Event Dispatcher.

Basic Usage


eventDispatcher.dispatchEvent(new SignOutEvent(SignOutEvent.SIGN_OUT));

Strong typing events

Optionally you can map commands to a concrete event class. This ensures that the command will only be executed if the event instance is of a specific event class.

    .map(FooEvent.FOO, FooEvent) //mapping the command to the concrete FooEvent class

//the command will NOT be executed, since the event instance is of type Event
eventDispatcher.dispatchEvent(new Event(FooEvent.FOO)); 

Event instance access inside commands

Commands are automatically injected with the event instance that triggered them, resolved to the type used for the mapping.

Concrete event types

    .map(SignOutEvent.SIGN_OUT, SignOutEvent) //the second parameter defines the type of event instance injection
public var event: SignOutEvent; //as mapped

public function execute():void{
    //do something useful with event

Abstract event types

    .map(SignOutEvent.SIGN_OUT, Event) //the second parameter defines the type of event instance injection
public var event: Event; //as mapped

public function execute():void{
    //do something useful with event

Note: this deviates from Robotlegs v1 functionality

In Robotlegs v1 an event instance was automatically mapped both to the concrete event type and the abstract Event type.

Mapping 'once' commands

If you know that you only want your command to fire once, and then be automatically unmapped:

    .map(SignOutEvent.SIGN_OUT, SignOutEvent)

Mapping guards and hooks

You can optionally add guards and hooks:

    .map(SignOutEvent.SIGN_OUT, SignOutEvent)

Guards and hooks can be passed as lists of classes, objects or function references.

Guards will be injected with the event that fired, and hooks can be injected with both the event and the command (these injections are then cleaned up so that events and commands are not generally available for injection).

For more information on guards and hooks check out:

  1. robotlegs.bender.framework.readme-guards
  2. robotlegs.bender.framework.readme-hooks

Note: strictly one mapping per-event-per-command

You can only make one mapping per event-command pair. You should do your complete mapping in one chain.

So - the following will issue a warning:

eventCommandMap.map(SomeEvent.STARTED).toCommand(SomeCommand); // warning

If you intend to change a mapping you should unmap it first.

Event Command Map Extension


This extension requires the following extensions:

  • EventDispatcherExtension

Extension Installation

_context = new Context().install(

Or, assuming that the EventDispatcherExtension has already been installed:


Extension Usage

An instance of IEventCommandMap is mapped into the context during extension installation. This instance can be injected into clients and used as below.

public var eventCommandMap:IEventCommandMap;