Module mapView not firing
Hi All,
I am pretty sure this is some sort of race condition issue but
could do with some fresh eyes on this. I have a Flex RL application
using Strays modular utility, one reason is I am not using
Flex modules i.e. mx:Module.
The problem is everything fires as I would expect i.e. Context
starts up, View is added to the stage and Module Mediator fires
onRegister(), my View has a nested component which has its
own Mediator e.g.
MyNestedComponentMediator.
Problem is a view mapping defined in the ModuleContext
is not firing onRegister()?
Here is my workflow to make it clearer what I am doing here:
1) I have modified slightly the org.robotlegs.utilities.modular.mvcs.ModuleContextView by adding a getter/setter for a view which extends SkinnableContainer. This is so that when I add a new module to the display list I can use addElement and provide a skinnable interface.
public class ModuleContextView extends Sprite implements IModuleContextView
{
protected var context:ModuleContext;
private var _view:SkinnableContainer;
public function ModuleContextView()
{
}
public function setModuleDispatcher(dispatcher:IModuleEventDispatcher):void
{
context.setModuleDispatcher(dispatcher);
}
public function startup():void
{
context.startup();
}
public function getModuleContext():ModuleContext{
return context;
}
public function get view():SkinnableContainer
{
return _view;
}
public function set view(value:SkinnableContainer):void
{
_view=value;
if(this.contains(_view)) this.removeChild(_view);
this.addChild(_view);
}
}
2) A module manager starts up the module:
public function integrateModules(modulesList:Vector.<ModuleContextView>, viewContainer:SkinnableContainer):void
{
trace("ADD THE MODULES");
var nextModule:ModuleContextView;
for each (nextModule in modulesList)
{
nextModule.setModuleDispatcher(_moduleEventDispatcher);
nextModule.startup();
viewContainer.addElement(nextModule.view);
}
}
3) Module assigns context and creates the (SkinnableContainer) view:
public function MyDisplayModule()
{
context=new MyDisplayModuleContext(this);
context.addEventListener(ContextEvent.STARTUP_COMPLETE, initView);
}
protected function initView(e:ContextEvent):void
{
trace("MyDisplayModule::Add MyDisplay view");
this.view=new MyDisplay();
}
4) Within the MyDisplayModuleContext onStartup() I then map my views:
mediatorMap.mapView(MyComponent,
MyComponentMediator);
5) MyDisplay has the component MyComponent in its display list:
<?xml version="1.0" encoding="utf-8"?>
<s:SkinnableContainer
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:view="com.newtriks.restricted.modules.mydisplay.restricted.view.*"
width="100%"
height="100%">
<s:layout>
<s:BasicLayout/>
</s:layout>
<view:MyComponent id="myComponent"/>
</s:SkinnableContainer>
This traces out in the following order:
- [trace] ADD THE MODULES
- [trace] MyDisplayModuleContext::startup
- [trace] onRegister in MyDisplayModuleMediator
- [trace] MyDisplayModule::Add MyDisplay view
- [trace] Added MyComponent to stage
So as you can see the actual module mediator is firing the onRegister() fine but although the MyComponent view mapping is showing in the contexts mediatorMap::mappingConfigByViewClassName the MyComponentMediator does not seem to be getting instantiate and thus firing its onRegister().
Anyone got any thoughts as to where I am synchronising startup incorrectly here?
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
| ? | Show this help |
|---|---|
| ESC | Blurs the current field |
Comment Form
| r | Focus the comment reply box |
|---|---|
| ^ + ↩ | Submit the comment |
You can use Command ⌘ instead of Control ^ on Mac
Support Staff 1 Posted by creynders on 12 Apr, 2011 11:28 AM
Do you call super.startup in MyDisplayModuleContext.startup before mapping MyComponent to MyComponentMediator?
Because it will send out a ContextEvent.STARTUP_COMPLETE event, which in this case means the component gets added to the display list before it's mapped to its mediator.
2 Posted by simon on 12 Apr, 2011 11:58 AM
Hi @creynders, this the order of events (I just verified debugging to make sure):
Support Staff 3 Posted by creynders on 12 Apr, 2011 12:56 PM
Looking at your code snippets again I think maybe the display list the view gets added to is not the display list that the modulecontext is listening to for the ADDED_TO_STAGE events.
In MyDisplayModule
you pass 'this' to the context, which means it will listen to the displaylist of MyDisplayModule, but the component is added to the viewContainer with
My guess is that's where it goes wrong?
That it gets added "above" MyDisplayModule instead of inside.
4 Posted by simon on 12 Apr, 2011 01:08 PM
My doubts lay in the same area, fresh eyes are always mega helpful mate thanks, I will look deeper. What I was trying to avoid was having to start editing ModuleContextView further for this.
5 Posted by Amy Blankenship on 21 Apr, 2011 12:24 AM
You may also want to think about whether your contexts that get created in Step 3 get garbage collected before they are used.
Support Staff 6 Posted by Stray on 02 May, 2011 03:35 PM
Closing this as I know you've now fixed it. Feel free to reopen it if you need more follow-up.
Stray
Stray closed this discussion on 02 May, 2011 03:35 PM.