tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/495-any-possible-way-to-make-modular-communication-work-in-command-partern-like-ordinary-robotlegsRobotlegs: Discussion 2012-03-30T08:59:43Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/141028262012-02-29T11:11:21Z2012-02-29T11:45:06ZAny possible way to make modular communication work in COMMAND Partern like ordinary robotlegs<div><p>Hi Dante,</p>
<p>All you have to do is:</p>
<ul>
<li>map your command in your shell’s context:</li>
</ul>
<p>moduleCommandMap.mapEvent(SomeModuleEvent.TRIGGER_COMMAND,
SomeModuleCommand, SomeModuleEvent);</p>
<ul>
<li>you can trigger the command from Module A or Module B:</li>
</ul>
<p>moduleDispatcher.dispatchEvent(new SomeModuleEvent
(SomeModuleEvent.TRIGGER_COMMAND));<br>
In SomeModuleCommand you can also dispatch events, if need be:</p>
<ul>
<li>let your command <strong>extend ModuleCommand</strong></li>
</ul>
<pre>
<code>
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”));
}
}</code>
</pre>
<ul>
<li>or, inject <strong>IModuleEventDispatcher</strong> in a regular
command:</li>
</ul>
<pre>
<code>
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”));
}
}</code>
</pre>
<ul>
<li>Mapping event listeners, if need be :</li>
</ul>
<p>[1] inter-module communication:</p>
<p>eventMap.mapListener(moduleDispatcher, SomeModuleEvent.MESSAGE,
handleModuleMessage);</p>
<p>[2] within a module:</p>
<p>eventMap.mapListener(eventDispatcher, SomeModuleEvent.MESSAGE,
handleModuleMessage);</p>
<p>If this doesn’t answer your question, please explain more
clearly what you want to achieve :)</p>
<p>Ondina</p></div>Ondina D.F.