tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/664-map-a-mediator-to-a-baseclassRobotlegs: Discussion 2012-12-11T11:51:35Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/199455882012-10-23T13:29:32Z2012-10-23T13:29:34ZMap a Mediator to a Baseclass.<div><p>Hello guys!</p>
<p>I've just run into a problem as building my robotlegs
application. I hope you'll be able to get me some help :) Let me
explain.</p>
<p>I have a world map within an external swc, that contains all the
countries in the world in specific movieclips. I need to be able to
map each and every one of them to a common mediator, say
"CountryMediator". My first idea was to create a baseclass that
every movieclip extends, but nothing was mapped to these classes
when they were added to the stage (and they surely were). I think
it's kind of normal as the concrete class that gets exported every
time is"France" "United Kingdom" "Spain", based on the class
"Country".</p>
<p>Is there any workaround so I just have to write one mapping rule
allowing me to map all the countries base on the Country class to
the Country mediator?</p>
<p>Thanks for you help!</p></div>thomas.pujolletag:robotlegs.tenderapp.com,2009-10-18:Comment/199455882012-10-23T14:05:23Z2012-10-23T14:05:23ZMap a Mediator to a Baseclass.<div><p>Hi Thomas,</p>
<p>If you make sure that Country implements an interface, you can
use the ViewInterfaceMediatorMap utility to have one rule manage
all instances of Country.</p>
<p>The util is here:</p>
<p><a href=
"https://github.com/piercer/robotlegs-extensions-ViewInterfaceMediatorMap">
https://github.com/piercer/robotlegs-extensions-ViewInterfaceMediat...</a></p>
<p>hth, if you have any problems with it do come back,</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/199455882012-10-23T14:08:04Z2012-10-23T14:08:04ZMap a Mediator to a Baseclass.<div><p>Hi Thomas,</p>
<p>Please take a look at the discussion and the utility I linked
below, and if you can’t find an answer in there, come back
with more questions:)</p>
<p><a href=
"http://knowledge.robotlegs.org/discussions/questions/290-mediating-views-as-interfaces">
http://knowledge.robotlegs.org/discussions/questions/290-mediating-...</a></p>
<p><a href=
"https://github.com/piercer/robotlegs-extensions-ViewInterfaceMediatorMap">
https://github.com/piercer/robotlegs-extensions-ViewInterfaceMediat...</a></p>
<p>Cheers,<br>
Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/199455882012-10-23T14:33:56Z2012-10-23T14:42:35ZMap a Mediator to a Baseclass.<div><p>Thanks for that ! i'm at this moment trying this
ViewInterfaceMediator.<br>
I have 6 WorldZones in my swc, based on the class WorldZone which
implements IWorldZone.</p>
<p>But for my 6 views, I get 5 errors (after the first
instantiation) saying:<br>
Warning: Injector already has a rule for type
"com.worldmap.view::WorldZoneMediator", named "".<br>
If you have overwritten this mapping intentionally you can use
"injector.unmap()" prior to your replacement mapping in order to
avoid seeing this message.</p>
<p>I have this in my mediator:<br>
<code>[Inject] public var worldZone:IWorldZone;</code></p>
<p>And this in my mediator map:<br>
<code>mediatorMap.mapView(IWorldZone,
WorldZoneMediator);</code></p>
<p>Am I doing this right? It's weird because it works once, and
then fires a warning.</p></div>thomas.pujolletag:robotlegs.tenderapp.com,2009-10-18:Comment/199455882012-10-23T16:47:09Z2012-10-23T16:47:09ZMap a Mediator to a Baseclass.<div><p>You’re getting those warnings because you’re
(probably) using robotlegs 1.5+ and SwiftSuspenders 1.6.</p>
<p>ViewInterfaceMediatorMap worked well with robotlegs v1.4, where
robotlegs and swiftsuspenders were in sync.</p>
<p>Stray had a patch for robotlegs’ Context.as, but I
can’t find any swcs reflecting the changes.<br>
Try using Stray’s fork of robotlegs.</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/199455882012-10-23T16:52:34Z2012-10-23T16:52:34ZMap a Mediator to a Baseclass.<div><p>Context.as:</p>
<p><a href=
"https://github.com/Stray/robotlegs-framework/blob/master/src/org/robotlegs/mvcs/Context.as#L169">
https://github.com/Stray/robotlegs-framework/blob/master/src/org/ro...</a></p>
<p><a href=
"https://github.com/Stray/robotlegs-framework/blob/master/src/org/robotlegs/mvcs/Context.as#L309">
https://github.com/Stray/robotlegs-framework/blob/master/src/org/ro...</a></p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/199455882012-10-25T08:53:00Z2012-10-25T08:56:25ZMap a Mediator to a Baseclass.<div><p>Thanks a lot for you help!</p>
<p>I've try to add the previous fixes to my code but it does not
seem to help avoiding the warnings. I'm sorry my comprehension of
RL is not good enough to allow me to fix this all by myself :/</p>
<p>Do you think I may construct my context the wrong way? I have
this:</p>
<p>public class ApplicationContext extends
InterfaceEnabledMediatorMapContext {</p>
<pre>
<code> public function ApplicationContext(contextView : DisplayObjectContainer) {
super(contextView, true);
}
override public function startup() : void {
new ModelsInitializer(injector);
new ServicesInitializer(injector);
new ApplicationStartupSequenceCommandsInitializer(commandMap);
new ApplicationCommandsInitializer(commandMap);
new ViewMediatorsInitializer(mediatorMap, contextView);
super.startup();
}
}</code>
</pre>
<p>And this:<br>
public class InterfaceEnabledMediatorMapContext extends Context
{</p>
<pre>
<code> public function InterfaceEnabledMediatorMapContext(contextView : DisplayObjectContainer = null, autoStartup : Boolean = true) {
super(contextView, autoStartup);
}
override protected function get mediatorMap() : IMediatorMap {
return _mediatorMap ||= new ViewInterfaceMediatorMap(contextView, createChildInjector(), reflector);
}
override public function set contextView(value : DisplayObjectContainer) : void {
if (_contextView != value) {
_contextView = value;
_injector.applicationDomain = getApplicationDomainFromContextView();
_commandMap = null;
_mediatorMap = null;
_viewMap = null;
unmapInjections();
mapInjections();
checkAutoStartup();
}
}
protected function unmapInjections() : void {
trace("InterfaceEnabledMediatorMapContext.as :: unmapInjections");
injector.unmap(IReflector);
injector.unmap(IInjector);
injector.unmap(IEventDispatcher);
injector.unmap(DisplayObjectContainer);
injector.unmap(ICommandMap);
injector.unmap(IMediatorMap);
injector.unmap(IViewMap);
injector.unmap(IEventMap);
}
}</code>
</pre>
<p>Thanks a lot!!!</p></div>thomas.pujolletag:robotlegs.tenderapp.com,2009-10-18:Comment/199455882012-10-25T10:13:48Z2012-10-25T10:13:48ZMap a Mediator to a Baseclass.<div><p>Hey Thomas,</p>
<p>No problem:)</p>
<p>It would be easier if you used robotlegs source and replaced
Context.as with the patched one. It would work with SwiftSuspenders
1.6, too. I’ll attach rl source with those changes.<br>
Let us know if it worked.</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/199455882012-10-25T10:31:03Z2012-10-25T10:31:03ZMap a Mediator to a Baseclass.<div><p>All right!</p>
<p>So if I understand the .zip contains the RL sources with the
patched Context.as, which will prevent me from getting stuff
like:<br>
Warning: Injector already has a rule for type
"com.worldmap.view::WorldZoneMediator", named "".<br>
If you have overwritten this mapping intentionally you can use
"injector.unmap()" prior to your replacement mapping in order to
avoid seeing this message.</p>
<p>And I should just add SwfSuspender 1.6 at the top of this,
right?</p></div>thomas.pujolletag:robotlegs.tenderapp.com,2009-10-18:Comment/199455882012-10-25T10:33:46Z2012-10-25T10:33:46ZMap a Mediator to a Baseclass.<div><p>Exactly.</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/199455882012-10-25T10:36:06Z2012-10-25T10:36:06ZMap a Mediator to a Baseclass.<div><p>It does not seem to work :( I didn't find the required adapters
in your .zip so I used so ones in the latest RL (1.5.2).</p>
<p>What do you think could cause this? My context extends this one,
which extend the one in your .zip:</p>
<pre>
<code>`public class InterfaceEnabledMediatorMapContext extends Context {
public function InterfaceEnabledMediatorMapContext(contextView : DisplayObjectContainer = null, autoStartup : Boolean = true) {
super(contextView, autoStartup);
}
override protected function get mediatorMap() : IMediatorMap {
return _mediatorMap ||= new ViewInterfaceMediatorMap(contextView, createChildInjector(), reflector);
}
}`</code>
</pre></div>thomas.pujolletag:robotlegs.tenderapp.com,2009-10-18:Comment/199455882012-10-25T10:39:50Z2012-10-25T10:39:50ZMap a Mediator to a Baseclass.<div><p>Have you deleted the rl swc and refreshed the project?</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/199455882012-10-25T12:44:58Z2012-10-25T12:44:58ZMap a Mediator to a Baseclass.<div><p>I have.<br>
I have the swf suspender SWC + your .zip source code + the two
adapters found in the latest robotlegs (master branch).</p>
<p>Still something seems to be wrong :(</p></div>thomas.pujolletag:robotlegs.tenderapp.com,2009-10-18:Comment/199455882012-10-25T12:48:18Z2012-10-25T12:48:18ZMap a Mediator to a Baseclass.<div><p>I need to tell my SWF works perfectly anyway, I just wonder if
it's going to impact performances, maybe not?</p></div>thomas.pujolletag:robotlegs.tenderapp.com,2009-10-18:Comment/199455882012-10-25T13:10:43Z2012-10-25T13:10:43ZMap a Mediator to a Baseclass.<div><p>One moment, please. I'm about to answer.</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/199455882012-10-25T13:41:19Z2012-10-25T13:41:19ZMap a Mediator to a Baseclass.<div><p>I’m back.</p>
<p>I guess it’s because you’re initializing your
context in actionscript.</p>
<p>Try initializing your context inside of the declaration tag,
like in piercer’s example:<br>
<fx:Declarations><br>
<mvcs:InterfaceEnabledMediatorMapContextExample
contextView="{this}"/><br>
</fx:Declarations></p>
<p>See if this works with the patched Context. If it doesn’t
work either, then maybe I gave you the wrong patch. I don’t
know whether there is a newer version or another solution.<br>
Stray would know more about this.</p>
<p>The warnings aren’t <em>that</em> important, and
won’t affect your app’s performance, so, I guess, you
could live with it;)</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/199455882012-10-25T13:51:54Z2012-10-25T13:51:54ZMap a Mediator to a Baseclass.<div><p>I'm not using flex so I won't be able to try this out, but I
think I'm going to stand by what I have right now if you say it
does not impact the application, thanks anyway for your time :) RL
rules!</p></div>thomas.pujolletag:robotlegs.tenderapp.com,2009-10-18:Comment/199455882012-10-25T14:28:24Z2012-10-25T14:28:24ZMap a Mediator to a Baseclass.<div><p>No problem, Thomas.<br>
I’ll close this discussion for now. You can re-open it, if
need be.</p>
<p>Cheers,<br>
Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/199455882012-11-12T14:18:32Z2012-11-12T14:18:32ZMap a Mediator to a Baseclass.<div><p>Hello guys,</p>
<p>I think I'll have to get through this another time, I have
issues when deleting views.<br>
No errors thrown but the flow gets broken at some point, after a
mediator deletion. After that, no other mediator of this type is
created.</p>
<p>Has anyone in one of his project a version of RL core + the
context fix + ViewInterfaceMediatorMap working?</p>
<p>Otherwise I'll have to create this by myself, although I didn't
get it right last time.</p>
<p>Thanks for you help :)</p></div>thomas.pujolletag:robotlegs.tenderapp.com,2009-10-18:Comment/199455882012-11-14T16:40:31Z2012-11-14T16:40:31ZMap a Mediator to a Baseclass.<div><p>Sorry, that you didn't get any answers. I don't know how to help
you.</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/199455882012-12-11T11:51:32Z2012-12-11T11:51:32ZMap a Mediator to a Baseclass.<div><p>Hi Thomas,</p>
<p>Have you found a solution?<br>
If not, have you considered using robotlegs 2? I don’t know
if you can afford to migrate your project to rl2, but rl2 offers
easier and cleaner solutions for your use case. Just saying:)</p>
<p>Ondina<br>
P.S. As you know, you can reopen the discussion, if you want to
answer</p></div>Ondina D.F.