Any possible way to make modular communication work in COMMAND Partern like ordinary robotlegs

Dante's Avatar

Dante

29 Feb, 2012 07:55 AM

Hi,everyone.
I have a question when I use org.robotlegs.utilities.modular to communicate between two modulars.
When I dipatch an inner-Event in Modular A ,It is obviously the mapped Command will excute.
But before I dispatchToModules a outer-Event in Modular A,I should set a "addEventListener" in Modular B in order to catch the outer-Event , then do some thing I want in this event Handler,it is unflexible.
I just want to make modular communication in Command Partern just like inner-Event do.
thanks for helping me

  1. Support Staff 1 Posted by Ondina D.F. on 29 Feb, 2012 11:11 AM

    Ondina D.F.'s Avatar

    Hi Dante,

    All you have to do is:

    • map your command in your shell’s context:

    moduleCommandMap.mapEvent(SomeModuleEvent.TRIGGER_COMMAND, SomeModuleCommand, SomeModuleEvent);

    • you can trigger the command from Module A or Module B:

    moduleDispatcher.dispatchEvent(new SomeModuleEvent (SomeModuleEvent.TRIGGER_COMMAND));
    In SomeModuleCommand you can also dispatch events, if need be:

    • let your command extend ModuleCommand
    
    
    public class SomeModuleCommand extends ModuleCommand
    {
    
    [Inject]
    public var event:SomeModuleEvent;
    
    override public function execute():void
    {
    
    // [1] inter-module communication:
    dispatchToModules(new SomeModuleEvent(SomeModuleEvent.MESSAGE, "external"));
    // [2] heard only by the module that triggered the command :
    [EDIT]
    In this case, only by the shell's mediator
    dispatch(new SomeModuleEvent(SomeModuleEvent.MESSAGE, "internal”));
    }
    }
    
    • or, inject IModuleEventDispatcher in a regular command:
    
    public class SomeModuleCommand extends Command
    {
    
    [Inject]
    public var event:SomeModuleEvent;
    [Inject]
    public var moduleDispatcher:IModuleEventDispatcher;
    
    override public function execute():void
    {
    
    moduleDispatcher.dispatchEvent(new SomeModuleEvent(SomeModuleEvent.MESSAGE, "external"));
    dispatch(new SomeModuleEvent(SomeModuleEvent.MESSAGE, "internal”));
    
    }
    }
    
    • Mapping event listeners, if need be :

    [1] inter-module communication:

    eventMap.mapListener(moduleDispatcher, SomeModuleEvent.MESSAGE, handleModuleMessage);

    [2] within a module:

    eventMap.mapListener(eventDispatcher, SomeModuleEvent.MESSAGE, handleModuleMessage);

    If this doesn’t answer your question, please explain more clearly what you want to achieve :)

    Ondina

  2. Ondina D.F. closed this discussion on 30 Mar, 2012 08:59 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac