tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/498-injecting-itemrenderer-data-into-mediatorRobotlegs: Discussion 2018-10-18T16:35:25Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/64233702011-04-04T14:12:36Z2011-04-04T14:12:36ZInjecting ItemRenderer data into mediator<div><p>Hi Luke,</p>
<p>Logic doesn't belong in mediators. Mediators should just take
view-events and send app events, and take app events and then use
the view API to pass the event data or carry out the required
action.</p>
<p>So - I'd say this stuff belongs in a view controller that wraps
your actual flex view.</p>
<p>Don't worry about injection - just figure out how you'd solve
this <em>without</em> injection (presumably through an API) and
then it will come together more simply.</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/64233702011-04-05T07:37:49Z2011-04-05T07:37:49ZInjecting ItemRenderer data into mediator<div><p>Hi Stray</p>
<p>Thanks for the feedback. Using a view controller sounds like a
good<br>
approach, but what would be the simplest way of implementing
it?</p>
<p>I thought about a way that the view controller could be
implemented using<br>
events as you suggested would be to use an event+command to update
the view.<br>
It does decouple the logic from the view but it seems to be
overkill<br>
(perhaps I just need to get used to this particular style).</p>
<p>It doesn't separate the data from the view, but maybe that's the
intrinsic<br>
nature of ItemRenderers and cannot be changed.</p>
<p>Mediator:<br>
[Inject] public var view:IRegisterChannelItemView;</p>
<p>override public function onRegister():void<br>
{ dispatch(new ViewEvent(ViewEvent.UPDATE, view)); }</p>
<p>UpdateViewCommand:<br>
[Inject] public var event:ViewEvent;</p>
<p>[Inject] public var locale:ILocaleModel;</p>
<p>public function execute():void<br>
{ event.view.caption =
event.view.data.languages[locale.currentLanguage];<br>
}</p>
<p>On Mon, Apr 4, 2011 at 4:19 PM, Stray <<br>
<a href=
"mailto:tender+ddf549f914a57c7e53f1e52d6006309ef03122af6@tenderapp.com">
tender+ddf549f914a57c7e53f1e52d6006309ef03122af6@tenderapp.com</a>>
wrote:</p></div>lukevanintag:robotlegs.tenderapp.com,2009-10-18:Comment/64233702011-04-05T08:08:43Z2011-04-05T08:08:43ZInjecting ItemRenderer data into mediator<div><p>Hi Luke - your view layer should be outside the robotlegs
framework.</p>
<p>So - your view controller is just a normal class. Imagine there
was no robotlegs involvement... how would you implement it?</p>
<p>In my architecture (which is AS3) my 'view' itself is actually a
skin drawn in Flash and brought in through an embedded asset in a
style sheet. Then there is a 'view controller' which is just the
View with the API on it, which manages the skin and any view logic.
The mediator has this view controller injected.</p>
<p>Would something similar work in your project?</p>
<p>If not then I'd hand the view to a viewController in your
mediator.</p>
<p>[Inject] public var skin:SomeFlexView;</p>
<p>protected var view:SomeViewController;</p>
<p>onRegister():void<br>
{</p>
<pre>
<code>view = new SomeViewController(skin);
//... do everything else as normal - but acting always on view and not skin</code>
</pre>
<p>}</p>
<p>onRemove():void<br>
{</p>
<pre>
<code>// don't forget to clean up any listeners from the viewController to the view
// this is only necessary if your view is coming and going from the stage
view.destroy();</code>
</pre>
<p>}</p>
<p>I'm afraid flex isn't my thing - so I hope this is helpful,</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/64233702011-04-05T10:37:39Z2011-04-05T10:37:39ZInjecting ItemRenderer data into mediator<div><p>Ah! Thinking about it that way makes much more sense. Using your
view<br>
controller suggestion works really well and scales as a general
solution for<br>
similar problems.</p>
<p>One of the other alternatives I came across is a presenter
model, which adds<br>
another model layer between the domain model and the view and
serves to map<br>
the domain data into display parameters.</p>
<p>On Tue, Apr 5, 2011 at 10:14 AM, Stray <<br>
<a href=
"mailto:tender+ddf549f914a57c7e53f1e52d6006309ef03122af6@tenderapp.com">
tender+ddf549f914a57c7e53f1e52d6006309ef03122af6@tenderapp.com</a>>
wrote:</p></div>lukevanin