开发者

Robotlegs Flex - How deal with mediators being initialized after creationComplete?

I'm trying to build a Flex application using the Robotlegs framework and don't know how to deal with the creation of mediators (-> onRegister being called) only after the creationComplete event of the view component.

My application loads several XML files at startup, models are created from the files and then dispatch events with the data. Problem: When "loading" embedded/local files at startup, the model events are dispatched way before the mediators listeneres are added, although they're mapped before triggering the initial data load in the main context.

Is anybody using robotlegs with flex and has foud a "cleaner" way around this, than manually dispatching an event in the mediators onRegister? As doing so the "automatic" mediation would not really be automatic anymore ...

Edit:

Minimal example code:

Context:

override public function startup( ):void{

mediatorMap.mapView( Edit开发者_如何学PythonorMenu, EditorMenuMediator );

commandMap.mapEvent( ContextEvent.STARTUP, LoadConfigurationCommand );

dispatchEvent( new ContextEvent( ContextEvent.STARTUP ) );

}

LoadConfigurationCommand:

[Inject] public var configurationService:IXMLLoader;

override public function execute():void{

configurationService.loadXML();

}

ConfigurationService:

public function loadXML(){

trace( "xml loaded" );

dispatch( new XMLLoadedEvent( XMLLoadedEvent.CONFIGURATION_LOADED, result ) );

}

EditorMenuMediator:

override public function onRegister( ):void{

trace( "menu onregister" );

addContextListener( XMLLoadedEvent.CONFIGURATION_LOADED, handleXmlLoaded, XMLLoadedEvent); }

The trace "menu onregister" is happening way before the trace "xml loaded", so the mediator's not listening when the XmlLoadedEvent is dispatched.


I approach this with the StateMachine and grab control of the order of operations. Another approach here would be to add the listener, but also inject the model and check it for data in onRegister. Either approach should put you in front of the race conditions.


I'm not expert in RobotLegs (I'm actually a Parsley addict), however, if you're using a Mediator pattern, that means that your mediator has direct access to the view itself. How about you create an interface class for all your views that has an init public function which your mediator could call after the onRegister.

Maybe Robotlegs has another way of doing it with metadata or events or something, but this is still valid.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜