Flex、Mate:事件路径——选择什么方式?

发布于 2024-11-03 03:14:20 字数 197 浏览 4 评论 0原文

想象一下,我们有一个对象正在调度某个事件,并且该对象应该对此事件执行某些操作。捕捉这个事件的正确方法是什么?我可以直接在我的对象中监听此事件还是应该让此事件通过 EventMap 传输?
示例:我有一个带有表单的弹出窗口。在提交表单时,我将向远程服务器发送请求并关闭此弹出窗口。在单击时执行弹出窗口关闭而不将自定义事件分派给 EventMap 在意识形态上是否正确?谢谢。

Imagine we have an object dispatching some event and this object should perform some action on this event. What's the right way of catching this event? May I listen to this event directly in my object or should I let this event travel through EventMap?
Example: I have a popup window with form. On submitting form, I'm going to send a request to remote server and close this popup. Is it ideologically correct to perform popup close on click without dispatching custom event to EventMap? Thanks.

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

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

发布评论

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

评论(2

静若繁花 2024-11-10 03:14:20

就我个人而言,我更喜欢负责创建视图或弹出窗口之类的对象,也应该负责它们的销毁。我更喜欢仅使用 Mate 来解决一些跨应用程序任务,尤其是客户端-服务器通信。因此,我更喜欢在组件级别使用普通的旧 ActionScript 事件处理。如果某个组件创建了弹出窗口,它可以监听一些提交事件并销毁弹出窗口。

另一种情况是弹出窗口是由 Mate 本身创建的(我的意思是在事件映射中)。在这种情况下,我认为在 Mate 处理程序中销毁窗口没有问题,该处理程序处理一些提交事件并向服务器执行请求并立即销毁窗口。

但无论如何,您应该使用简单的规则来调度 Mate 事件(我的意思是由事件映射处理的事件):不要调度一些低级别的事件。您应该将它们转换为反映相应应用程序级别上的业务逻辑的事件。在您的情况下,您不应该考虑将表单提交为两个操作:请求服务器和关闭窗口。从窗口的角度来看,这只是表单提交,窗口不应该关心是否会有服务器请求或从 SharedObject 甚至从某种模型读取数据。因此,窗口应该调度提交事件,并且 Mate 映射应该处理该事件,并在同一处理程序中生成请求和窗口销毁。这样,您就可以使用视图,而无需知道视图是在弹出窗口中还是在本机 AIR 窗口中。只需调整你伴侣的事件地图即可。

并且不要忘记 Mate 的地图可以是分层的。这样就可以划分业务逻辑的事件处理级别。

As for me personally I prefer the object which responsible for creation of something like views or pop ups should be responsible for their destroying too. And I prefer to use Mate only for solving some cross-application tasks especially client-server communications. So I prefer using plain old ActionScript event handling on a component level. And if some component created pop up window it can listen some submit event and destroy pop up.

Another case if pop up was created by Mate itself (I mean in event map). In this case I see no problem to destroy window in Mate handler which handles some submit event and performs request to the server and destroys window at once.

But anyway you should dispatch Mate events (I mean events which handled by event map) using the simple rule: do not dispatch some low level events. You should convert them to events reflecting business logic on a corresponding application level. In your case you shouldn't consider submitting your form as two operations: requesting server and closing window. From window's point of view it is just form submitting and window shouldn't care if there will be server request or reading data from SharedObject or even from some kind of model. So window should dispatch submit event and Mate map should handle this event and produce request and window destroying in the same handler. This way you can use your view without knowing if view is in pop up or maybe in native AIR window. Just adjust your Mate's event map.

And don't forget Mate's map can be hierarchical. So you can divide levels of handling event of business logic.

飘逸的'云 2024-11-10 03:14:20

是的,这是正确的,您不需要仅为关闭窗口调度事件,
因为事件的主要目的是通知外部/父母某些事情已完成/更改

yes it is correct, and you dont need to dispatch event just for Closing window,
because main purpose of events to inform external/parents that some thing done/changed

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