tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/12478-inherited-mediators-mappingRobotlegs: Discussion 2014-12-05T12:07:54Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/350614082014-10-24T11:03:00Z2014-10-24T11:03:00ZInherited mediators mapping<div><p>Hi,</p>
<p>I'm looking to do exactly what is said here in the following
post:</p>
<p><a href=
"http://knowledge.robotlegs.org/discussions/robotlegs-2/11567-inherited-mediators-mapping">
http://knowledge.robotlegs.org/discussions/robotlegs-2/11567-inheri...</a></p>
<p>But when I do it, I get:</p>
<p>Warning: Injector already has a mapping for
xxx.view::BaseView|.<br>
If you have overridden this mapping intentionally you can use
"injector.unmap()" prior to your replacement mapping in order to
avoid seeing this message. Exception fault: Error: Injector mapping
override for type [class BaseView] with name</p>
<p>Any thoughts? Thanks.</p></div>Jonotag:robotlegs.tenderapp.com,2009-10-18:Comment/350614082014-10-24T11:44:44Z2014-10-24T11:44:44ZInherited mediators mapping<div><p>Hi Jono,</p>
<p>can you paste the relevant code for your mappings?</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/350614082014-10-24T11:50:50Z2014-10-24T11:50:50ZInherited mediators mapping<div><p>Hi Ondina,</p>
<pre>
<code>mediatorMap.mapMatcher(new TypeMatcher().allOf(BaseView, InterfaceView)).toMediator(InterfaceMediator);
mediatorMap.mapMatcher(new TypeMatcher().allOf(BaseView, MainMenuView)).toMediator(MainMenuMediator);
mediatorMap.mapMatcher(new TypeMatcher().allOf(BaseView, SideMenuView)).toMediator(SideMenuMediator);</code>
</pre></div>Jonotag:robotlegs.tenderapp.com,2009-10-18:Comment/350614082014-10-24T12:08:31Z2014-10-24T12:08:31ZInherited mediators mapping<div><p>I can't see anything wrong with the mappings.<br>
Is it possible to attach your app or a simplified example
reproducing the issue?</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/350614082014-10-24T12:15:31Z2014-10-24T12:15:31ZInherited mediators mapping<div><p>Sure thing - will put an example together now. Thanks.</p></div>Jonotag:robotlegs.tenderapp.com,2009-10-18:Comment/350614082014-10-24T12:31:41Z2014-10-24T12:31:41ZInherited mediators mapping<div><p>Here is a simplified version of the issue. Thanks for having a
look.</p></div>Jonotag:robotlegs.tenderapp.com,2009-10-18:Comment/350614082014-10-24T12:35:11Z2014-10-24T12:35:11ZInherited mediators mapping<div><p>ok I'll take a look and report back asap</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/350614082014-10-24T15:32:14Z2014-10-24T15:32:14ZInherited mediators mapping<div><p>I found the culprit. In your InterfaceView.init() you add 2 more
views to the stage. The problem is, that by that time,
InterfaceView isn't added to stage yet. When the 2 views are added
after InterfaceView is on stage, everything works fine.<br>
I tried it in a Flex app as well. It works without any issues. It
is a pure as3 problem, due to the way mediators are created.</p>
<p>I've attached 2 files. Yours modified and another one, which is
a Flex app.<br>
The modification to your code:</p>
<p>I created the context in the added to stage handler of the main
view.<br>
I added InterfaceView in the afterInitilizing handler of the
context, so that you don't need to do it in a command.<br>
I added MainMenuView and SideMenuView on the added to stage of
InterfaceView.</p>
<p>I created 2 more packages: baseViews and otherViews, where I use
an interface - IBaseView that is injected into
JustABaseMediator.</p>
<p>The mappings:</p>
<pre>
<code>mediatorMap.mapMatcher(new TypeMatcher()
.allOf(IBaseView, AnotherView))
.toMediator(AnotherMediator);
mediatorMap.mapMatcher(new TypeMatcher()
.allOf(IBaseView, SomeView))
.toMediator(SomeMediator);</code>
</pre>
<p>Just take a look at the classes to see what I mean. Too much to
describe in detail and too little time right now;)</p>
<p>hth</p>
<p>P.S. Your app is now an AIR one, because it was easier for me to
work with in FlashBuilder</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/350614082014-10-25T00:53:38Z2014-10-25T00:53:38ZInherited mediators mapping<div><p>Thanks very much for this. I'll look into the examples and let
you know if I have any more questions. On initial look, is it
regarded good practise to use context.afterInitializing to start a
project?</p></div>Jonotag:robotlegs.tenderapp.com,2009-10-18:Comment/350614082014-10-27T11:15:09Z2014-12-05T12:07:54ZInherited mediators mapping<div><p>You're welcome, Jono.</p>
<blockquote>
<p>On initial look, is it regarded good practise to use
context.afterInitializing to start a project?</p>
</blockquote>
<p>afterInitializing is exactly what the name suggests: a new
context has been created, the context has installed all extensions,
and the mappings/wirings/configurations are done for all your
classes, so that they are ready to work and interact with each
other. It's not about good or bad practice. It just depends on your
use case, whether you need to do anything after the context has
been initialized or not. For example, afterInitializing would be a
convenient place to :</p>
<ul>
<li>
<p>add Views to a contextView (for navigational purposes)</p>
</li>
<li>
<p>make a service call to which a certain mediator should react
(avoiding race conditions)</p>
</li>
<li>
<p>have access to the shared event dispatcher</p>
</li>
<li>
<p>many other scenarios, but I can't think of any others right
now</p>
</li>
</ul>
<p>Your SetupCommand suggested to me that you needed to add a view
after context initialization, that's why I showed you how to use
context.afterInitializing.</p>
<p>In my projects I use option a or c from my response in this
discussion:</p>
<p><a href=
"http://knowledge.robotlegs.org/discussions/robotlegs-2/4493-dispatching-context-initialization-complete-with-common-eventdispatcher#comment_28136082">
http://knowledge.robotlegs.org/discussions/robotlegs-2/4493-dispatc...</a></p></div>Ondina D.F.