tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/1-mapping-and-injection-with-base-classesimplementations-regarding-viewcomponents-and-mediatorsRobotlegs: Discussion 2012-08-29T09:16:20Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/4782782009-10-21T19:49:14Z2009-10-21T19:49:15ZMapping and Injection with base-classes/implementations regarding ViewComponents and Mediators<div><p>Since this site also exists, i wan't to try it for my first
problem with RL:<br>
Ich have the following Classes I talk about here:</p>
<ul>
<li>MultiTextViewerBase.as<br>
<code>public class MultiTextViewerBase extends
SkinnableContainer...</code><br>
has all component-logic to handle multiple textElements.</li>
<li>StartPage.mxml<br>
<code><viewer:MultiTextViewerBase ...</code><br>
wich defines a text-layout and the mapping for textElements.</li>
<li>MultiTextViewerMediator.as<br>
<code>public class MultiTextViewerMediator extends Mediator
implements IMediator</code><br>
which knows everything that is needed to connect any implementation
of MultiTextViewerBase to the app.</li>
</ul>
<p>My first attempt to use StartPage (beside puting it on the
displaylist) was to write the following inside
<code>context.startup()</code>:<br></p>
<pre>
<code>mediatorMap.mapView(MultiTextViewerBase,MultiTextViewerMediator);</code>
</pre>
<p>and this inside of MultiTextViewerMediator:<br></p>
<pre>
<code>[Inject]
public var view:MultiTextViewerBase;</code>
</pre>
<p>but with this there was no Mediator registered for StartPage
(what i can see in the log and from the "non-behaviour" of the
component).</p>
<p>so thinking maybe it needs the concrete class of the component
to make mapping work, i added this line after the above in
<code>context.startup()</code>:<br></p>
<pre>
<code>mediatorMap.mapView(MultiTextViewerBase,MultiTextViewerMediator);
mediatorMap.mapView(StartPage, MultiTextViewerMediator);</code>
</pre>
<p>When starting the app (which always adds a StartPage to the
displaylist ;) ) I recieved
"error-swiftsuspenders-viewBase-in-Mediator" (see the attached
file)</p>
<p>to exclude if there is an error when a mediator is mapped twice
i uncommented the fist of the two lines in
<code>context.startup()</code>.<br></p>
<pre>
<code>//mediatorMap.mapView(MultiTextViewerBase,MultiTextViewerMediator);
mediatorMap.mapView(StartPage, MultiTextViewerMediator);</code>
</pre>
<p>but it threw the same error.</p>
<p>The only solution left, I could think of right now was to change
the class of view in MultiTextViewerMediator to StartPage.<br></p>
<pre>
<code>[Inject]
public var view:StartPage;</code>
</pre>
<p>Even if this does not solve my problem, because I wanted to map
one mediator to multiple component-implementations (ideally without
naming the concrete class(es), but naming it(them) to map to a more
specific mediator when I want to), this removed the error-message
and (of course) did the mapping and injection / onRegister as
usual.</p>
<p>Is, could or will there be any way to do what I wan't?</p>
<p>Thx for help, karfau</p></div>karfautag:robotlegs.tenderapp.com,2009-10-18:Comment/4782782009-10-21T20:59:57Z2009-10-21T20:59:57ZMapping and Injection with base-classes/implementations regarding ViewComponents and Mediators<div><p>Hi Karfau,</p>
<p>I think I see what you're getting at. Could you build a tiny
example app (smallest possible) that exhibits this same behavior -
that would really help us determine the nature of the problem.</p>
<p>Many thanks,<br>
Shaun</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/4782782009-10-21T21:02:42Z2012-07-20T15:43:14ZMapping and Injection with base-classes/implementations regarding ViewComponents and Mediators<div><p>An internal ticket was created for this discussion</p></div>Systemtag:robotlegs.tenderapp.com,2009-10-18:Comment/4782782009-10-21T22:24:16Z2009-10-21T22:57:07ZMapping and Injection with base-classes/implementations regarding ViewComponents and Mediators<div><p>Here u go.</p>
<p>Should my attempt work or does it need to be implemented?</p>
<p>(the zipfile only contains the source, using RL v0.95)</p>
<p>It uses FlexSDK 4 (i don't think thats a problem?)</p>
<p>To get the errormessage uncomment lines 13+14 and comment out
line 17+18 in view.BasicMediator.</p></div>karfautag:robotlegs.tenderapp.com,2009-10-18:Comment/4782782009-10-21T23:18:34Z2009-10-21T23:18:34ZMapping and Injection with base-classes/implementations regarding ViewComponents and Mediators<div><p>Ah! Currently mediators can only be mapped to concrete view
classes.<br>
This is for performance. We could look into enabling mapping to<br>
abstract classes as a framework addon, but the performance cost
is<br>
going to be pretty substantial. I hope that's not too disapointing
-<br>
I've been pondering this issue for some time myself.</p>
<p>Shaun Smith<br>
<a href=
"http://shaun.boyblack.co.za">http://shaun.boyblack.co.za</a></p>
<p>On 22 Oct 2009, at 12:24 AM, karfau
<a>tender+d43dd5815964509c984208610c4f8cfbcdd792fcf@tenderapp.com<br/</a>
> wrote:</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/4782782009-10-22T11:15:37Z2009-10-22T11:15:37ZMapping and Injection with base-classes/implementations regarding ViewComponents and Mediators<div><p>Hey Karfau,</p>
<p>I've thought about that issue quite extensively, too.
Unfortunately,<br>
Shaun is absolutely right: There's no solution that would have<br>
acceptable performance for this problem.</p>
<p>To give you a quick impression of what we would have to do,
here's<br>
what happens now for every view that's added to the display
list:</p>
<ul>
<li>get the class name through reflection (and cache it after first
retrieval)</li>
<li>make a lookup in our mediator mapping table to see if a
mediator is mapped for that (concrete) view class<br></li>
<li>create the mediator if it has been found</li>
</ul>
<p>And here's what we'd have to do for your use case to work:</p>
<ul>
<li>get the class name, all super class names and all implemented
interfaces through reflection (and cache that, but much less<br>
efficiently)<br></li>
<li>make a lookup in our mediator mapping table for <em>each</em>
of these class names and interfaces<br></li>
<li>create the mediator if it has been found</li>
</ul>
<p>Keeping in mind that all of that has to be done for absolutely
each<br>
view that's added to the display list, I guess you understand
why<br>
that's a performance problem.</p>
<p>cheers,<br>
till</p></div>Till Schneidereittag:robotlegs.tenderapp.com,2009-10-18:Comment/4782782009-10-22T21:58:04Z2009-10-22T21:58:21ZMapping and Injection with base-classes/implementations regarding ViewComponents and Mediators<div><p>thx for this longer explanation.<br>
Im sure I just don't have any idea of how this works/ is
implemented.</p>
<p>But I have a small hope left, that I could get the small
addition to the current solution, because my problem is not, that I
don't want to map my concrete view (that would be great, but
somehow lazy). I would love to map all concrete view-classes that
can be handles by ONE Mediator-class (BasicMediator in my
ExampleApp), if in this BasicMediator I could make the type the
view-component to ViewComponentBase.</p>
<p>So I think (when I look at the errormessage) that my problem is
the injection that is not working, because it doesn't find the
class to inject. But if the injector (not sure if I name the parts
right here) would change the finding of the given viewComponent(vc)
to inject for a property(p) from an</p>
<p><code>classOf(vc)==classOf(p)</code></p>
<p>to an</p>
<p><code>vc is classOf(p)</code></p>
<p>this would make me happy.</p>
<p>Is this understandable? (I hope)<br>
possible (because some kind of new idea)? (I fear not)</p>
<p>This will be my last attempt in this direction I think.</p>
<p>Just for testing if I have understood u right:<br>
Another approach would be not to do this heavy stuff for(/at) all
viewComponents/mediators but only if requested, like in:<br>
<code>mediatorMap.mapGenericView( concreteViewComponentClass:*,
mediatorClass:Class,
genericAttributeClassOfViewComponentInMediator:*,
auto...);</code></p>
<p>e.g.(again with classes from my example-project)<br>
<code>mediatorMap.mapGenericView( ViewComponentImpl,
ViewComponentBaseMediator, ViewComponentBase);</code></p>
<p>and would this still be heavy stuff? as it is not like<br></p>
<blockquote>
<ul>
<li>get the class name, all super class names and all implemented
interfaces through reflection (and cache that, but much less<br>
efficiently)<br></li>
<li>make a lookup in our mediator mapping table for <em>each</em>
of these class names and interfaces</li>
</ul>
</blockquote>
<p>but names a concrete class to map?</p>
<p>(I can still imagine thatt this is not needed "enough" to make
the efford if this would require much code to change. But maybe
this is a way to not make the mapping generic but only make the
mediator generic.)</p>
<p>So if all of this doesn't work, I need to copy the code of the
ViewCompoenteBaseMediator into multiple classes and change the type
of the viewComponent to the implementations and map all of
these?</p>
<p>wow, still a lot of questions, thx for the support so far,</p>
<p>karfau</p></div>karfautag:robotlegs.tenderapp.com,2009-10-18:Comment/4782782009-10-22T22:35:28Z2009-10-22T22:35:28ZMapping and Injection with base-classes/implementations regarding ViewComponents and Mediators<div><p>Aha! That you can do:</p>
<p>mediatorMap.mapModule("view::ViewComponentImpl",
ViewComponentBase,<br>
BasicMediator );<br>
mediatorMap.mapModule("view::ViewComponentImpl2",
ViewComponentBase,<br>
BasicMediator );</p>
<p>The first param (the Fully Qualified Class Name, or FQCN - note
the<br>
"::") is used for the concrete mapping, the second param is what
is<br>
injected on Mediator registration.</p>
<p>Hope that helps!</p>
<p>Cheers,<br>
Shaun</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/4782782009-10-22T22:40:25Z2009-10-22T23:03:05ZMapping and Injection with base-classes/implementations regarding ViewComponents and Mediators<div><p>ok, im not using modules, but this also works with normal
viewcomponents?</p>
<p>I will test if this does what i want on monday.</p>
<p>thx, and cu</p></div>karfautag:robotlegs.tenderapp.com,2009-10-18:Comment/4782782009-10-22T22:54:38Z2009-10-22T22:54:38ZMapping and Injection with base-classes/implementations regarding ViewComponents and Mediators<div><p>Yes, it is badly named I think, but it works with normal
view<br>
components. I tested it out on the code you sent me and it works,
so<br>
hopefully it's what you were looking for.</p>
<p>cheers,</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/4782782009-10-22T23:02:49Z2009-10-22T23:12:42ZMapping and Injection with base-classes/implementations regarding ViewComponents and Mediators<div><p>Couldn't wait to see if it works the way I want: tested it right
now:<br>
Jippie, thats what I wanted!!!</p>
<p>by the way this:<br>
<code>mediatorMap.mapModule( getQualifiedClassName(StartPage),
MultiTextViewerBase, MultiTextViewerMediator);</code> also works
and is typesafe ;)</p>
<p>(So I aks myself: how could I have asked to get this answer in
the start ;) )</p>
<p>(double) thx, karfau</p></div>karfautag:robotlegs.tenderapp.com,2009-10-18:Comment/4782782009-10-22T23:14:07Z2009-10-22T23:14:07ZMapping and Injection with base-classes/implementations regarding ViewComponents and Mediators<div><p>Awesome! Glad to hear it :)</p>
<p>Cheers,<br>
Shaun</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/4782782009-10-23T12:25:03Z2009-10-23T12:25:03ZMapping and Injection with base-classes/implementations regarding ViewComponents and Mediators<div><p>Wow, that's actually something I didn't know as well.
Immediate<br>
dramatic increase in usefulness of mapModule for me!</p></div>Till Schneidereittag:robotlegs.tenderapp.com,2009-10-18:Comment/4782782009-10-23T17:28:54Z2009-10-23T17:28:54ZMapping and Injection with base-classes/implementations regarding ViewComponents and Mediators<div><p>Yeh, mapModule is REALLY badly named.. has nothing to do with
Flex<br>
modules.. dealing with Flex modules was just the first place I
needed<br>
it :)</p></div>Shaun Smith