tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/7109-processing-views-automaticallyRobotlegs: Discussion 2013-10-12T10:29:40Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/293257082013-10-11T08:35:54Z2013-10-11T08:36:39ZProcessing views automatically<div><p>Hi Philip,</p>
<blockquote>
<p>My current (working) solution is to mediate the view and
manually process it in the mediator initializer.</p>
</blockquote>
<p>What do you mean by that? Setting some properties on the
view?</p>
<p>If so, then you could do this in your config:</p>
<pre>
<code>var someProperty:String = "someValue";
injector.map(String).toValue(someProperty);
viewProcessorMap.map(SimpleView).toInjection();</code>
</pre>
<p>then, in SimpleView:</p>
<pre>
<code>[Inject]
public var someProperty:String;</code>
</pre>
<p>The moment SimpleView is added to the stage, it has access to
someProperty, which has been set in the config.</p>
<blockquote>
<p>Assuming you're listening to your contextView, any view that
lands on the contextView can be processed if it matches a mapping
you've already created.</p>
</blockquote>
<p>Yeah, it is a misleading formulation:)<br>
You don't have to listen to your contextView explicitly. That's a
robotlegs-context duty. The moment your context has been
initialized, it is able to handle the views that are added and
removed from stage through the ViewManager, as explained in the
sentence above the one you cited:</p>
<p>"In Robotlegs 2, stage-event listening is centralised to a
ViewManager. The ViewManager listens for views landing on the
stage, and being removed from stage, and informs interested
parties, such as the viewProcessorMap, accordingly. "</p>
<p>Did I answer your question?</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/293257082013-10-11T14:42:51Z2013-10-11T14:42:51ZProcessing views automatically<div><p>Hi Ondina,</p>
<p>thank you for your answer.</p>
<blockquote>
<p>My current (working) solution is to mediate the view and
manually process it in the mediator initializer.</p>
</blockquote>
<p>by this, I meant the following</p>
<pre>
<code> [Inject]
public var view : SomeView;
[Inject]
public var viewProcessorMap : IViewProcessorMap;
override public function initialize() : void
{
viewProcessorMap.process(view);
}</code>
</pre>
<p>Your example is working out fine, thanks. I just can't seem to
get it to work for Starling sprites. Not sure what goes on behind
the scenes, but perhaps the issue lies with the
StarlingViewMapExtension and how the Starling displayObjects are
mapped.</p></div>Philiptag:robotlegs.tenderapp.com,2009-10-18:Comment/293257082013-10-11T15:59:50Z2013-10-11T15:59:50ZProcessing views automatically<div><p>The ViewProcessorMap doesn't work with the Starling extensions I
know of . They also have some issues with robotlegs' shared event
dispatcher, because Starling has its own custom EventDispatcher (
for more details on this see:<br>
<a href=
"http://knowledge.robotlegs.org/discussions/problems/3815-injector-is-missing-a-mapping-to-handle-injection-into-property">
http://knowledge.robotlegs.org/discussions/problems/3815-injector-i...</a>)</p>
<p>If you tell me what exactly do you want to achieve, we could
find alternative solutions together.</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/293257082013-10-12T08:26:52Z2013-10-12T08:26:52ZProcessing views automatically<div><p>Ah ok, I wasn't aware of that.<br>
Well, I am perfectly fine with the workaround listed above. Perhaps
something along these lines:<br></p>
<pre>
<code>// AppConfig
var someProperty:String = "someValue";
injector.map(String).toValue(someProperty);
viewProcessorMap.map(IProcessable).toInjection();
mediatorMap.map(IProcessable).toMediator(ProcessableViewMediator);</code>
</pre>
<pre>
<code>// ProcessableViewMediator
[Inject]
public var view : IProcessable;
[Inject]
public var viewProcessorMap : IViewProcessorMap;<br>
override public function initialize() : void
{
viewProcessorMap.process(view);
}</code>
</pre>
<p>This would work for Starling views.</p></div>Philiptag:robotlegs.tenderapp.com,2009-10-18:Comment/293257082013-10-12T10:29:39Z2013-10-12T10:29:39ZProcessing views automatically<div><p>Cool:) I'll mark this discussion as resolved. You can re-open
it, if need be.</p>
<p>Cheers,<br>
Ondina</p></div>Ondina D.F.