tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/703-share-mediatormap-between-modulesRobotlegs: Discussion 2013-01-12T12:43:35Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/231277262012-12-26T14:03:34Z2012-12-26T14:03:34ZShare mediatorMap between modules?<div><p>Hello,</p>
<p>I'm struggling a little bit understanding what you're wanting to
achieve. You mention this:</p>
<blockquote>
<p>So command cannot create mediator for a view from module</p>
</blockquote>
<p>But why does the command need to create a mediator at all?
Surely the mediators that have been registered in the module
context will just be auto-created when the correct views land on
stage?</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/231277262012-12-27T08:13:48Z2012-12-27T08:13:49ZShare mediatorMap between modules?<div><blockquote>
<p>Surely the mediators that have been registered in the module
context will just be auto-created when the correct views land on
stage?</p>
</blockquote>
<p>They doesnt seem to. Mediator is already mapped to view in
module context at the moment when ADDED_TO_STAGE is fired by the
view, but mediator's onRegister is not entered.</p>
<p>Isn't it because module listens to ADDED_TO_STAGE on its
contextView (which is spark.modules.Module component) and view is
added into parent application contextView?</p></div>witchfindertag:robotlegs.tenderapp.com,2009-10-18:Comment/231277262012-12-27T11:16:10Z2012-12-27T11:16:11ZShare mediatorMap between modules?<div><p>Addition: when I'm trying to pass application as contextView for
module like this</p>
<pre>
<code>[Inject]
public function set parentInjector(value:IInjector):void {
var contextView:DisplayObjectContainer = this.parentApplication as DisplayObjectContainer;
context = new EffectsEditModuleContext(contextView, true, value, ApplicationDomain.currentDomain);
}</code>
</pre>
<p>then module mediator (spark.modules.Module component) itself
isn't getting Registered</p></div>witchfindertag:robotlegs.tenderapp.com,2009-10-18:Comment/231277262012-12-27T15:50:37Z2012-12-27T15:50:37ZShare mediatorMap between modules?<div><blockquote>
<p>module listens to ADDED_TO_STAGE on its contextView (which is
spark.modules.Module component) and view is added into parent
application contextView?</p>
</blockquote>
<p>Ah! So are you using the modules purely as class definition
containers then? It sounds like the view components that you are
mapping inside the modules are not actually being added into the
context view for those modules?</p>
<p>If that's the case then I wouldn't really bother with the
Modular utility at all. Instead I would make the modules implement
an interface. Something like:</p>
<pre>
<code>IViewMappingProvider
function getViewMappings():<ViewMapping>
ViewMapping
public var viewClass:Class;
public var mediatorClass:Class;</code>
</pre>
<p>After loading a module you'd then cast it to
IViewMappingProvider and pull out the list of ViewMappings, loop
through them, map the mediators into your root context and then
construct and add the views to stage.</p>
<p>Or, is that not quite what you're wanting to do?</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/231277262012-12-28T07:41:19Z2012-12-28T07:41:20ZShare mediatorMap between modules?<div><p>No, my modules do use own context views, but sometimes they need
to add something outside.<br>
I solved my problem like it was suggested 2 threads under.<br>
In my ApplicationView:</p>
<pre>
<code>protected function preinitializeHandler(event:FlexEvent):void {
var contextView:DisplayObjectContainer = SystemManager.getSWFRoot(this) as DisplayObjectContainer;
this.context = new AppContext(contextView);
}</code>
</pre>
<p>and in module:</p>
<pre>
<code>[Inject]
public function set parentInjector(value:IInjector):void {
context = new MyModuleContext(this.parentApplication as DisplayObjectContainer, true, value, ApplicationDomain.currentDomain);
}</code>
</pre>
<p>Module and application now use same context view.</p></div>witchfindertag:robotlegs.tenderapp.com,2009-10-18:Comment/231277262013-01-03T19:49:48Z2013-01-03T19:49:48ZShare mediatorMap between modules?<div><p>Hi, I'm closing this thread for now. If you have other questions
please re-open or create a new thread. Thanks.</p></div>Shaun Smith