Flex Cairngorm 3 演示模型初始化

发布于 2024-11-19 21:54:09 字数 1139 浏览 4 评论 0原文

好的,我打开了一个 TitleWindow...并且定义了 6 个状态。我对所有视图使用演示模型模式。我发现了一个令人沮丧的细微差别。当我告诉我的窗口进入 XXX 状态时,控件必须初始化,因为 Flex 中的状态使用延迟加载。所以...我的 PM 代码显示 myTextArea.text 爆炸并显示“无法访问...”因此作为解决方法,我在控件上创建了一些creationComplete 事件以向 PM 注册控件。因此,当状态更改时,文本区域最终会初始化,并在创建完成时调用 PM.registerTextArea() 来设置对其的引用。然后在该函数中我运行我的代码... myTextArea.text .. 等等。

这看起来像一个丑陋的黑客,我讨厌它。有什么方法可以等到整个状态创建完毕然后在 PM 上调用代码吗?我尝试过 Enterstate...但此事件似乎在状态控件准备就绪之前触发。

我尝试添加评论,但我想编辑是我能做到这一点的唯一方法...

对大家:感谢您的宝贵反馈。我正在做一些稍微偏离直接PM的事情。每个视图都有一个 viewController(我这样称呼它们)。它有点像我自己的委托/数据提供者的混合体。但这是没有意义的。在处理状态时,Flex 组件的生命周期才是最痛苦的。如果您更改状态.. 没有事件表明“我处于此状态的所有组件都已准备就绪”。唯一说“我们改变了状态”的事件。因此,我在状态更改时触发的代码正在尝试与尚未准备好的组件进行通信。因此,从我看来,似乎没有设计模式或完美的方法来确保所有组件都在某个状态下创建,除非在该状态中的每个组件上使用creationComplete来注册它已准备好...如果不这样做,那么您获得竞争条件。无论框架或设计模式如何,这似乎都是一个根本问题。

textarea 是一个简单的 PM 修复..只需将其绑定到 pm 值即可。但也有其他时候我做不到。

具体来说,一旦达到该状态,我就会尝试将视频附加到显示器上。这是通过 addchild 完成的。无论我在哪里执行此操作..我需要知道在调用 addchild 之前 videoDisplay 已完成加载。我什至尝试了 currentStateChange 事件,因为文档说它最后触发......但是唉......状态中的组件仍在初始化。所以看来creationComplete是我唯一的选择。也许保持代码干净的唯一明智的方法是在进入状态后使用 as 创建整个事物(视频显示和视频)。我只是希望 Flex 框架能够提供一些事件来帮助我,而不是在 as 中动态构建所有内容。

ok so I have a TitleWindow that I open up... and I have 6 states defined. I am using the Presentation model pattern for all of my views. I have discovered a frustrating nuance. When I tell my window to go to XXX state, the controls have to initialize since the states in flex use lazy loading. so... my PM code that says myTextArea.text bombs out and say "cannot access..." so as a work around, I made some creationComplete events on my controls to register the control with the PM. So when the state changes, the textarea finally initializes and on creationComplete calls PM.registerTextArea() which sets a reference to it. then in that function I run my code... myTextArea.text.. etc.

This seems like such a ugly hack that I hate it. Is there any way to wait until the entire state in created then call code on the PM? I have tried enterstate... but this event seems to fire before the state controls are ready.

I tried to add a comment, but I guess editing is the only way I can do this...

to everyone: thanks for the great feedback. I am doing something slightly off straight PM. Every view has a viewController (as I call them). Its kinda my own hybrid of a delegate / dataprovider. But this is moot. It's the flex component lifecycle when dealing with states that is the pain. if you change state.. there is no event to say "all my components in this state are ready". only event to say "we changed state". so my code that fires on state change is trying to talk to components that aren't ready yet. So from what I see, there seems to be no design pattern or perfect way to ensure that all components are created in a state unless using creationComplete on every component in the state to register it is ready... if you don't, you get a race condition. Regardless of frameworks or design patterns, this seems to be a root issue.

The textarea is an easy PM fix.. just bind it to the pm value. But there are other times I can't.

Specifically, I am trying to attach video to a display once I get to that state. This is done via addchild. regardless of where I do it.. I need to know that the videoDisplay is done loading before I call addchild. I even tried currentStateChange event since docs say that fires last... but alas.. the components in the state are still initializing. So it seems that creationComplete is my only option. Maybe the only sane way to keep to clean code is to create the entire thing (videodisplay and video) using as once the state is entered. I just hoped the flex framework had events to ehlp me here rather than buiilding everything on the fly in as.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彼岸花ソ最美的依靠 2024-11-26 21:54:09

由于您的 PM 引用了可视组件 (myTextArea),因此这并不是完全纯粹的演示模型形式。它似乎更像是一种监督演示者/控制器类型的设置。

话虽这么说,我解决你的问题的方法是直接使用完整的演示者(根本不了解视图)或使用完整的控制器(视图实现控制器通过其进行通信的接口)。在 Flex 中使用演示者的优点是,您可以创建可绑定值,例如文本或 selectedItem,并且视图将在该变量上线时绑定到该变量,因此处理 Flex 组件生命周期的问题就消失了。

Since your PM has a reference to a visual component (myTextArea), this isn't a completely pure form of a presentation model. It appears to be more of a supervising presenter / controller type of setup.

That being said, the way I would fix your problem would be to use a complete presenter outright ( no knowlege of the view at all ) or use a complete controller ( view implements an interface through which the controller communicates ). The advantage of using a presenter in Flex is that you can create a bindable value such as text or selectedItem, and the view will bind to that variable whenever it comes online so the issues dealing with the lifecycle of Flex components go away.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文