tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/395-myconfigconfigure-not-getting-calledRobotlegs: Discussion 2012-11-20T10:14:32Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/209170032012-11-16T13:37:41Z2012-11-16T13:37:41ZMyConfig.configure() not getting called.<div><p>Hi Joel,</p>
<p>I do the configuration like this:</p>
<p>MainView.as</p>
<pre>
<code>package
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.text.TextField;
import yourdomain.config.ApplicationContext;
import yourdomain.views.components.HelloView;
public class MainView extends Sprite
{
private var context:ApplicationContext;
public function MainView()
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
addEventListener(Event.ADDED_TO_STAGE, onViewAdded);
}
protected function onViewAdded(event:Event):void
{
trace("ContextView.onViewAdded(event)");
context = new ApplicationContext(this);
createChildren();
}
public function createChildren():void
{
trace("ContextView.createChildren()");
var myText:TextField = new TextField();
myText.x = 10;
myText.width = 400;
myText.text = "MAIN VIEW";
addChild(myText);
var helloView:HelloView = new HelloView();
helloView.x = 10;
helloView.y = 100;
addChild(helloView);
}
}
}</code>
</pre>
<p>ApplicationContext.as</p>
<pre>
<code>package yourdomain.config
{
import flash.display.DisplayObjectContainer;
import org.swiftsuspenders.Injector;
import robotlegs.bender.bundles.mvcs.MVCSBundle;
import robotlegs.bender.extensions.eventCommandMap.api.IEventCommandMap;
import robotlegs.bender.extensions.logging.InjectorLoggingExtension;
import robotlegs.bender.extensions.mediatorMap.api.IMediatorMap;
import robotlegs.bender.framework.context.api.IContext;
import robotlegs.bender.framework.context.impl.Context;
import yourdomain.views.components.HelloView;
import yourdomain.views.mediators.HelloMediator;
import yourdomain.views.mediators.MainMediator;
public class ApplicationContext
{
private var injector:Injector;
private var mediatorMap:IMediatorMap;
private var commandMap:IEventCommandMap;
private var context:IContext;
private var _contextView:DisplayObjectContainer;
public function ApplicationContext(contextView:DisplayObjectContainer = null, autoStartup:Boolean = true)
{
trace("ApplicationContext.ApplicationContext(contextView, autoStartup)");
context = new Context();
context.extend(MVCSBundle, InjectorLoggingExtension);
//context.logLevel=LogLevel.DEBUG;
context.configure(contextView);
_contextView = contextView;
injector = context.injector;
mediatorMap = injector.getInstance(IMediatorMap);
commandMap = injector.getInstance(IEventCommandMap);
mapMappingCommands();
}
private function mapMappingCommands():void
{
trace("ApplicationContext.mapMappingCommands()");
//usually,I do the mappings in separate commands
mediatorMap.mapView(HelloView).toMediator(HelloMediator);
mediatorMap.mapView(MainView).toMediator(MainMediator);
mediatorMap.handleView(_contextView, MainMediator);
}
}
}</code>
</pre>
<p>Does that help?<br>
Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/209170032012-11-16T14:34:17Z2012-11-16T14:34:17ZMyConfig.configure() not getting called.<div><p>In the latest version you have to supply the view wrapped in a
ContextView object. I think I updated all the readmes, but it's
possible that I missed some.</p>
<p>.configure(new ContextView(this))</p>
<p>Shaun Smith<br>
<a href=
"http://twitter.com/darscan">http://twitter.com/darscan</a><br>
<a href=
"http://shaun.boyblack.co.za">http://shaun.boyblack.co.za</a></p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/209170032012-11-16T17:09:44Z2012-11-16T17:09:45ZMyConfig.configure() not getting called.<div><p>Thanks for the example Ondina. It always helps understand intent
when I see things used differently. For now I want to address
Shaun's comment first and then I'll contemplate a different
structure.</p>
<p>@Shaun, here's my updated bootstrap:</p>
<pre>
<code>public class HelloApp extends Sprite
{
private var _context:IContext;
public function HelloApp()
{
trace("HelloApp");
_context = new Context()
.install(MVCSBundle)
.configure(HelloConfig)
.configure(new ContextView(this));
}
}</code>
</pre>
<p>but now I get an injector error.<br>
Error: Injector is missing a mapping to handle injection into
property "contextView" of object "[object HelloConfig]" with type
"HelloConfig".</p>
<p>I'm not sure how to handle that mapping.</p></div>Joel Stranskytag:robotlegs.tenderapp.com,2009-10-18:Comment/209170032012-11-16T17:51:43Z2012-11-16T17:51:44ZMyConfig.configure() not getting called.<div><p>I'm borrowing this approach from <a href=
"https://github.com/darscan/robotlegs-demos-HelloFlash">https://github.com/darscan/robotlegs-demos-HelloFlash</a>
by the way.</p></div>Joel Stranskytag:robotlegs.tenderapp.com,2009-10-18:Comment/209170032012-11-16T18:58:56Z2012-11-16T19:01:56ZMyConfig.configure() not getting called.<div><p>This works:</p>
<p><strong>View</strong></p>
<p>_context = new Context()</p>
<p>.install(MVCSBundle)</p>
<p>.install(ContextViewExtension)</p>
<p>.configure(AppConfig)</p>
<p>.configure(new ContextView(this));</p>
<p><strong>AppConfig.as</strong></p>
<p>[Inject] public var contextView:ContextView;</p>
<p>//===contextView type is <strong>ContextView</strong> !!!</p>
<p>…..</p>
<p>private function init():void<br>
{</p>
<p>// add the view that has the mediator mapped to it</p>
<p>contextView.view.addChild(new MessageWriterView());</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/209170032012-11-16T19:21:23Z2012-11-16T19:21:23ZMyConfig.configure() not getting called.<div><p>Ah yes, I'll need to update those examples. The ContextView is
mapped into the injector as <code>ContextView</code>. Inject that
and you can access the wrapped view object.</p>
<p>It may seem like a bit of a silly change, but mapping a raw
DisplayObjectContainer directly into the injector always felt odd
and unclear to me. The new way is much more explicit I think. Also,
the whole <code>context.configure(this)</code> thing was super
unclear.</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/209170032012-11-16T19:22:48Z2012-11-16T19:22:51ZMyConfig.configure() not getting called.<div><p>Sorry if this triple posted. I'm not seeing this thread
update.</p>
<p>I thought that the MVCSBundle already installed
ContextViewExtension.<br>
Changing the type to ContextView worked. It seems redundant to have
to say contextView.view</p>
<p>So now the only problem is, the event I dispatch from my view
constructor is not being caught by its mediator.</p>
<p>HelloView.as</p>
<pre>
<code> private var _tf:TextField;
public function HelloView()
{
super();
trace("HelloView()");
_tf = new TextField();
_tf.text = "Hello World";
addChild(_tf);
dispatchEvent(new HelloViewEvent(HelloViewEvent.HELLO));
}</code>
</pre>
<p>HelloMediator.as</p>
<pre>
<code> public class HelloMediator extends Mediator
{
[Inject]
public var view:HelloView;
public function HelloMediator()
{
super();
}
override public function initialize():void{
addViewListener(HelloViewEvent.HELLO, handleHello, HelloViewEvent);
}
private function handleHello(event:HelloViewEvent):void{
trace("Hello View Event Detected");
}
}</code>
</pre></div>Joel Stranskytag:robotlegs.tenderapp.com,2009-10-18:Comment/209170032012-11-16T19:32:37Z2012-11-16T19:32:39ZMyConfig.configure() not getting called.<div><p>Ok, got the mediator to catch it but had to move to the dispatch
to onAddedToStage. I wouldn't normally dispatch within the
constructor anyway but I'm just hacking at the moment to see how
the parts work together.<br>
Not sure if it means anything but at first I didn't remove the
ADDED_TO_STAGE listener within onAddedToStage as is common and my
event got handled twice in the mediator. Once I added the remove it
worked as expected but I'm curious as to why that happened.</p>
<p>See, this is why I love robotlegs so much. From this extremely
basic example, I already feel like I could dive into a large
app.</p></div>Joel Stranskytag:robotlegs.tenderapp.com,2009-10-18:Comment/209170032012-11-16T19:42:19Z2012-11-16T19:42:19ZMyConfig.configure() not getting called.<div><p>Yup, I imagine that your custom event was being fired too soon
(a view object must be constructed before it can be parented). Not
sure about the double added-to-stage though - that's a weird
one.</p>
<p>The ContextViewExtension is indeed installed by the MVCSBundle -
it's job is to watch the <code>configure()</code> method for a
<code>ContextView</code> object and map it into the injector:</p>
<p><a href=
"https://github.com/robotlegs/robotlegs-framework/blob/master/src/robotlegs/bender/extensions/contextView/ContextViewExtension.as">
https://github.com/robotlegs/robotlegs-framework/blob/master/src/ro...</a></p>
<p>Similarly, the <code>StageSyncExtension</code> inspects
<code>ContextView</code> objects and auto initializes the
Context:</p>
<p><a href=
"https://github.com/robotlegs/robotlegs-framework/blob/master/src/robotlegs/bender/extensions/stageSync/StageSyncExtension.as">
https://github.com/robotlegs/robotlegs-framework/blob/master/src/ro...</a></p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/209170032012-11-20T10:14:31Z2012-11-20T10:14:31ZMyConfig.configure() not getting called.<div><p>Joel, this seems to be resolved. If you want to continue this
discussion, feel free to reopen it.</p></div>Ondina D.F.