tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/3714-mediation-of-interfacesRobotlegs: Discussion 2013-07-18T15:00:45Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/276079672013-07-03T13:15:32Z2013-07-03T13:15:32ZMediation of Interfaces<div><p>Currently we have one mediator for each view.<br>
For example if we have a lot of buttons and we want to implement
IClickable, we have one instance of each mediator for each button,
and if we have more interfaces, like IScalable or IHideable
....</p>
<p>Is it possible to make implementation or certain type of
mediator that has list of all views that have certain interface,
and since we are manipulating interface methods it will be the same
for each view.</p>
<p>Would this save on resources, or is there different approach to
this?</p></div>matejtag:robotlegs.tenderapp.com,2009-10-18:Comment/276079672013-07-03T14:33:56Z2013-07-03T14:33:56ZMediation of Interfaces<div><p>Hey Matej,</p>
<p>Is this what you’re after?</p>
<pre>
<code>mediatorMap.mapMatcher(new TypeMatcher()
.anyOf(ISpaceShip, IRocket))
.toMediator(SpaceCraftMediator);</code>
</pre>
<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>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/276079672013-07-03T15:56:14Z2013-07-03T15:56:14ZMediation of Interfaces<div><p>Maybe what you meant was this:</p>
<p>FirstView implements IFirstBehaviour, ISecondBehaviour<br>
SecondView implements ISecondBehaviour</p>
<p>And you map the behaviours:</p>
<p>
mediatorMap.map(IFirstBehaviour).toMediator(FirstBehaviourMediator);<br>
mediatorMap.map(ISecondBehaviour).toMediator(SecondBehaviourMediator);</p>
<p>Then you inject IFirstBehaviour into FirstBehaviourMediator, and
ISecondBehaviour into SecondBehaviourMediator</p>
<p>So when FirstView is added to the stage, both mediators will be
created, and you can apply both behaviours to FirstView.<br>
SecondView will only have the behaviour defined in
ISecondBehaviour.</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/276079672013-07-04T09:02:28Z2013-07-05T10:23:04ZMediation of Interfaces<div><p>Lets put it like this :)</p>
<p>Is it possible to have instance of mediator for 15 buttons. They
all have the same method, so when new IButton is added to stage, we
just update the list inside the mediator with the new view.
Currently I think we have one instance per button.<br>
Matej Šimunić<br>
Developer</p>
<p>GV3 UX</p></div>matejtag:robotlegs.tenderapp.com,2009-10-18:Comment/276079672013-07-04T09:31:55Z2013-07-04T10:58:16ZMediation of Interfaces<div><p>When you add several instances of the same view to the stage,
each instance will have its own mediator.</p>
<p>If you add different Views, that implement the same interface
(IFirstBehaviour), and you mapped them like so:</p>
<p>
mediatorMap.map(IFirstBehaviour).toMediator(FirstBehaviourMediator);</p>
<p>each view will have its separate mediator.</p>
<p>What you’re asking is <strong>one</strong> mediator for
<strong>multiple views</strong>, right?</p>
<p>You are thinking of mapping the mediator as an interface? If so,
as far as I know, that’s not possible. You can only map
concrete mediator classes. I might be wrong though.</p>
<p>Why do you think is a bad idea to map to behaviours, as I
suggested in my last post?</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/276079672013-07-05T10:20:07Z2013-07-05T11:38:02ZMediation of Interfaces<div><p>Alternative solution:</p>
<p>If you need to set properties to lots of view instances and you
don’t want to have a mediator for each instance of the view,
you might want to consider using hooks and guards, and provide
mediation through views’ parent mediator.</p>
<p>Say, you mapped the views as interfaces like this:</p>
<pre>
<code>viewProcessorMap.mapMatcher(new TypeMatcher().anyOf(IFirstBehaviour, ISecondBehaviour))
.toProcess(new FastPropertyInjector({colorsVO:ColorsVO}))
.withHooks(SomeBehaviourHook)
.withGuards(IfColorIsRed);</code>
</pre>
<p>By using the viewProcessorMap you can inject properties into
your views, if you want to.<br>
If you don’t want to inject any properties, use
.toNoProcess() instead of toProcess.</p>
<p>In your hook you inject IFirstBehaviour and ISecondBehaviour and
call the view’s API to let it do what you need it to do.<br>
The hook will do its job and then it gets gc-ed.</p>
<p>If you need to let your view implementing the above interfaces
send data back to the framework, you let it dispatch an event, and
the mediator of the parent view can handle it (if the event bubbles
= true)</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/276079672013-07-05T11:29:07Z2013-07-05T11:29:07ZMediation of Interfaces<div><p>I like this, will check it out later :)</p>
<p>thanks<br>
Matej Šimunić<br>
Developer</p>
<p>GV3 UX</p>
<p>
––––––––––––––––––––––––––––––––––––––<br>
Note: Privileged/Confidential information may be contained in this
message and may be subject to legal privilege.<br>
Access to this e-mail by anyone other than the intended is
unauthorised.<br>
If you are not the intended recipient (or responsible for delivery
of the message to such person), you may not use, copy, distribute
or deliver to anyone this message (or any part of its contents ) or
take any action in reliance on it.</p></div>matej