有什么方法可以将 valueCommit 生命周期添加到 Actionscript 中的非 mxml 组件吗?
根据我的经验,mxml 组件使用的 invalidate/commitProperties 模型非常有用,我希望能够在我的 ActionScript 应用程序的域模型对象中使用它。我该如何向我的对象添加类似的生命周期事件?是否有全局对象生命周期管理器?
The invalidate/commitProperties model used by mxml components is very useful, in my experience, and I'd like to be able to make use of it in domain model objects in my actionscript applications. How can I go about adding lifecycle events like that to my objects? Is there a global object lifecycle manager?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如 Robert Bak 所指出的,您基本上需要自己为非 UI 组件实现这样的机制。
我发现这是在模型类上使用的一种非常有用的技术,因为当您的模型类不是简单的数据传输对象(即它们具有任何类型的多属性逻辑)时,它可以显着减少绑定属性更新的“颠簸”封装在其中。
由于我的用例是模型对象,因此我不需要 IInvalidating 的所有方法。
这是我的具体实现,作为您自己努力的起点。请注意,这来自我们使用的名为 RAFModel 的“基本模型类”,并且这是针对 Flex 4 SDK 的。
As noted by Robert Bak, you're essentially on your own to implement such a mechanism for non-UI components.
I've found this a very useful technique to use on model classes, since it can dramatically reduce the "thrashing" of bound-property updates when your model classes are not simple data transfer objects - i.e. they have any kind of multi-property logic encapsulated within them.
Since my use-case is for model objects, I didn't need all the methods of IInvalidating.
Here's my particular implementation as a starting point for your own efforts. Note that this comes from a "base model class" we use called RAFModel and that this is for the Flex 4 SDK.
Invalidation 和 commitProperties 未链接到 MXML(您可以将其用作组件),但它链接到 Flex 管理的视觉组件生命周期(因为它们是唯一的生命周期)需要与Flash逐帧渲染同步)。因此,除非您谈论的是视觉组件,否则它不会开箱即用。
但是,如果您希望为非可视类实现相同的机制,您可能应该从实现 IInvalidating (docs)并创建一种机制,在需要完成验证时调用 validateNow() 函数。
Invalidation and commitProperties isn't linked to MXML (you can use it with as components) but it is linked to the flex managed visual component lifecycle (as they are the only ones which need to be synchronized with the flash frame by frame rendering). So unless you're talking about visual components it will not work out of the box.
But if you're looking to implement the same mechanism for your non-visual classes, you should probably start by implementing IInvalidating (docs) and creating a mechanism that calls the validateNow() function when the validation needs to be done.
Flex 组件生命周期旨在处理用户界面组件的创建、销毁以及其间的更改。我个人认为这种方法不适合非用户界面组件。
如果需要,您可以在域模型对象中扩展 UIComponent,然后将该域模型作为子级添加到容器中。然后它将经历 Flex 组件生命周期验证阶段(commitProperties、updateDisplayList 和measure)。
但是,我不推荐这种方法。
The Flex Component LifeCycle is designed to handle a User Interface Component's creation, destruction, and changes during the time in between. I, personally, do not find the approach appropriate for non-User Interface components.
You could, if you wanted, extend UIComponent in your domain model objects and then add that domain model as a child to a container. it would then go through the Flex Component LifeCycle validation phases (commitProperties, updateDisplayList, and measure).
But, I would not recommend that approach.