tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/28799-injectviewas-in-rl2Robotlegs: Discussion 2017-11-17T11:39:28Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/431677032017-08-10T06:46:11Z2017-08-10T06:46:11ZinjectViewAs in RL2<div><p>Hello Ruben,</p>
<p>mediatorMap.mapMatcher:</p>
<pre>
<code>mediatorMap
.mapMatcher(new TypeMatcher()
.allOf(IBaseView, ISubView, SomeView))
.toMediator(SomeMediator);
mediatorMap
.mapMatcher(new TypeMatcher()
.allOf(IBaseView, IAnotherSubView, AnotherView))
.toMediator(AnotherMediator);</code>
</pre>
<p>Please take a look at these answers:</p>
<p><a href="http://knowledge.robotlegs.org/discussions/robotlegs-2/17748-different-mediators-for-same-view">http://knowledge.robotlegs.org/discussions/robotlegs-2/17748-differ...</a></p>
<p><a href="http://knowledge.robotlegs.org/discussions/robotlegs-2/3714-mediation-of-interfaces">http://knowledge.robotlegs.org/discussions/robotlegs-2/3714-mediati...</a></p>
<p>robotlegs documentation on github:</p>
<p><a href="https://github.com/robotlegs/robotlegs-framework/tree/master/src/robotlegs/bender/extensions/mediatorMap#making-mappings">https://github.com/robotlegs/robotlegs-framework/tree/master/src/ro...</a></p>
<p>Let me know whether it's what you are looking for or not.<br>
Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/431677032017-08-10T10:12:22Z2017-08-10T10:12:24ZinjectViewAs in RL2<div><p>Hi Ondina,</p>
<p>thanks for your swift response! This seems to work quite well, thank you. However I have one problem now: In Robotlegs 1 we were doing this:</p>
<pre>
<code>mediatorMap.mapView(BuyPopup, BuyPopupMediator, IPopup);
//... some other specific Popup / Mediator combinations
mediatorMap.mapView(IPopup, BasePopupMediator);</code>
</pre>
<p>In Robotlegs 1 this results in all Popups having exactly one Mediator. Only popups that would not have a hit against one of the specific combinations would receive a BasePopupMediator. (Note we were using an InterfaceMediatorMap I found online somwhere). So every popup ends up with exactly one Mediator. Only popups that dont have their specific mediator defined will receive a BasePopup Mediator.</p>
<p>I am now trying to recreate the behavior in Robotlegs 2 like this:</p>
<pre>
<code>mediatorMap.mapMatcher(new TypeMatcher().allOf(IPopup, LoginPopup)).toMediator(LoginPopupMediator);
mediatorMap.map(IPopup).toMediator(BasePopupMediator);</code>
</pre>
<p>However Robotlegs 2 does not seem to stop when the first Mediator was created, so I end up with LoginPopup having 2 mediators: A LoginPopupMediator and a BasePopupMediator.</p>
<p>Is there a way to make sure that only the first mediator is used? We have hundreds of specific popup classes, so using .noneOf() would seem overly complex and hard to maintain.</p>
<p>Thanks in advance,<br>
Ruben</p></div>Rubentag:robotlegs.tenderapp.com,2009-10-18:Comment/431677032017-08-10T15:41:29Z2017-08-10T15:41:29ZinjectViewAs in RL2<div><p>No problem, Ruben.</p>
<p>You shouldn't try to map the BasePopupMediator.</p>
<p>I would create a derived class, let's say, DerivedPopupMediator, that would simply extend BasePopupMediator. It would be responsible for all IPopup views with the exception of LoginPopUp.</p>
<pre>
<code>mediatorMap
.mapMatcher(
new TypeMatcher()
.allOf(IPopup)
.noneOf(LoginPopup))
.toMediator(DerivedPopupMediator);
mediatorMap
.mapMatcher(new TypeMatcher()
.allOf(IPopup, LoginPopup))
.toMediator(LoginPopupMediator);</code>
</pre>
<p>Does this help?</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/431677032017-08-11T07:03:12Z2017-08-11T07:03:12ZinjectViewAs in RL2<div><p>Maybe even better than the previous solution:</p>
<p>Let all views that you don't want to be mediated by the DerivedPopupMediator implement yet another interface, a dummy interface, IExceptionView, without functionality. LoginPopup view would implement IPopup and IExceptionView.</p>
<pre>
<code>mediatorMap
.mapMatcher(
new TypeMatcher()
.allOf(IPopup)
.noneOf(IExceptionView)
)
.toMediator(DerivedPopupMediator);
mediatorMap
.mapMatcher(new TypeMatcher()
.allOf(IPopup, LoginPopup))
.toMediator(LoginPopupMediator);</code>
</pre></div>Ondina D.F.