tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/931-intermodular-communication-bestpracticeRobotlegs: Discussion 2013-04-08T10:06:39Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/255149992013-03-03T21:44:13Z2013-03-03T21:44:13ZIntermodular communication (Best)Practice<div><p>Hello Zuzu,</p>
<p>Unfortunately there isn't an official approach to this just
yet.</p>
<p>The challenge is that each context get its own isolated Event
Dispatcher, so if you are wanting to dispatch an event from the
Shell and have a Command fire inside a Module, you need to relay
the event somehow.</p>
<p>I'd really like to come up with an Extension to simply event
relaying. One that doesn't rely on mediators or digging into the
parent's injector.</p>
<p>As for the ScopedEventDispatcherExtension, you might need to use
it in the end anyway. Even though you don't intend on having
separate communication channels, it's the only way to "share"
secondary dispatchers between a Shell and its Modules. Otherwise
all you have is completely isolated dispatchers for each
context.</p>
<p>I'm working on something but struggling a bit with the API and
preventing circular relays (causing infinite event loops).</p>
<p>In the meantime, here's how you might do it manually:</p>
<ol>
<li>
<p>Install the ScopeEventDispatcherExtension into the Shell and
Module contexts. By default this will map an IEventDispatcher named
"global" into the Shell context which the Modules will inherit.</p>
</li>
<li>
<p>Create a config for setting up the relaying</p>
<pre>
<code>class MyConfig implements IConfig
{
[Inject]
public var local:IEventDispatcher;
[Inject(name="global")]
public var global:IEventDispatcher;
public function configure():void
{
// relay an event from the global to the local dispatcher
global.addEventListener("blah", local.dispatchEvent);
}
}</code>
</pre></li>
<li>
<p>Dispatch specific events along the global dispatcher</p>
<pre>
<code>[Inject(name="global")]
public var global:IEventDispatcher;
global.dispatchEvent(new Event("blah"));</code>
</pre></li>
</ol>
<p>If you have any ideas for a nicer API for such a mechanism
please let me know. I'd like to get this sorted before the RL2
release (which is pretty soon).</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/255149992013-03-04T14:30:10Z2013-03-04T14:30:10ZIntermodular communication (Best)Practice<div><p>Hello Shaun & Zuzu,</p>
<p>Is there a similar solution for signals?</p>
<p>I am now mapping the Signals to the commands on the correct
ISignalCommandMap because I manually find with of the children
injectors to use. But I would be gratefull to have a similar
temporary solution as the ScopeEventDispatchers for the
Signals.</p></div>Gustavotag:robotlegs.tenderapp.com,2009-10-18:Comment/255149992013-03-04T20:33:30Z2013-03-04T20:34:04ZIntermodular communication (Best)Practice<div><p>Hi Gustavo,</p>
<p>RL won't bundle any official Signals support until Signals
reaches a stable (v1.0) release.</p>
<p>In the meantime you could try your hand at creating your own
ScopedSignal extension. The ScopedEventDispatcherExtension is
pretty simple:</p>
<p><a href=
"https://github.com/robotlegs/robotlegs-framework/blob/master/src/robotlegs/bender/extensions/scopedEventDispatcher/ScopedEventDispatcherExtension.as">
https://github.com/robotlegs/robotlegs-framework/blob/master/src/ro...</a></p>
<p>Let us know how you get on.</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/255149992013-03-05T06:57:38Z2013-03-05T06:57:38ZIntermodular communication (Best)Practice<div><p>Allright !</p>
<p>I'll let yo u know how it goes</p></div>Gustavotag:robotlegs.tenderapp.com,2009-10-18:Comment/255149992013-03-05T07:58:23Z2013-03-05T07:58:23ZIntermodular communication (Best)Practice<div><p>Well, The first problem I'm encountering also makes me wonder
how is this supposed to work on the IEventDispatcher version.</p>
<p>As I can see is the extension mapping the EventDispatcher to a
newly created instance when initializing. And is mapping it with
the name/s give ('global') by default.</p>
<p>From what I can see, and please correct me if I'm wrong, this
means that only 1 event dispatcher can be named as 'global'
right?</p>
<p>This might even be pulled-off with a global super powerful
EventDispatcher but I believe it can't go so good when using one
ISignal.</p>
<p>I'm now thinking on an alternative approach, and will be
posting.<br>
If you have any ideas please let me know.</p></div>Gustavo