Robotlegs Flex - 如何处理创建完成后初始化的调解器?
我正在尝试使用 Robotlegs 框架构建 Flex 应用程序,但不知道如何仅在视图组件的creationComplete 事件之后处理中介器的创建(-> onRegister 被调用)。
我的应用程序在启动时加载多个 XML 文件,从这些文件创建模型,然后使用数据调度事件。 问题:在启动时“加载”嵌入/本地文件时,模型事件会在添加中介侦听器之前调度,尽管它们是在触发主上下文中的初始数据加载之前进行映射的。
有人使用带有 Flex 的 Robotlegs 并找到了一种“更干净”的方法来解决这个问题,而不是在中介器 onRegister 中手动调度事件吗?这样做,“自动”调解将不再真正是自动的......
编辑:
最小示例代码:
上下文:覆盖公共函数startup():void{
mediatorMap.mapView( EditorMenu, EditorMenuMediator );
commandMap.mapEvent(ContextEvent.STARTUP, LoadConfigurationCommand);
dispatchEvent( new ContextEvent( ContextEvent.STARTUP ) );
}
加载配置命令:[注入] public var configurationService:IXMLLoader;
覆盖公共函数execute():void{
configurationService.loadXML();
}
配置服务:公共函数loadXML(){
trace(“xml 已加载”);
dispatch( new XMLLoadedEvent( XMLLoadedEvent.CONFIGURATION_LOADED, result ) );
}
EditorMenuMediator:重写公共函数 onRegister( ):void{
trace(“注册菜单”);
addContextListener(XMLLoadedEvent.CONFIGURATION_LOADED,handleXmlLoaded,XMLLoadedEvent);
}
跟踪“menu onregister”发生在跟踪“xml returned”之前,因此在调度 XmlLoadedEvent 时中介器不会监听。
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( EditorMenu, 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用 StateMachine 来实现此目的,并控制操作顺序。这里的另一种方法是添加侦听器,同时注入模型并检查 onRegister 中的数据。任何一种方法都应该让你处于竞争条件的前面。
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.
我不是 RobotLegs 方面的专家(我实际上是欧芹瘾君子),但是,如果您使用调解器模式,则意味着您的调解器可以直接访问视图本身。如何为所有视图创建一个接口类,该类具有一个 init 公共函数,中介者可以在 onRegister 之后调用该函数。
也许 Robotlegs 有另一种方法来处理元数据或事件或其他东西,但这仍然有效。
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.