为什么我应该使用 Ext.dispatch 而不是直接调用控制器代码? [英] Why should I use Ext.dispatch rather than calling controller code directly?

查看:27
本文介绍了为什么我应该使用 Ext.dispatch 而不是直接调用控制器代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Sencha Touch 中使用 [相对较新的] MVC 位时,我发现 90% 的调度调用类似于:

When using the [relatively new] MVC bits in Sencha Touch I find that 90% of my dispatch calls look something like:

Ext.dispatch({
    controller: "customers",
    action: 'show',
    record: record
});

那很好,我喜欢将流程委托给单独的控制器代码,而不是复杂的事件路径,但我还没有看到比仅仅做类似的事情有什么优势:

That's fine, and I like delegating the flow to the seperate controller code, rather than complicated paths of events, but I have yet to see any advantage over just doing something like:

controllers.customers.show({
    record: record
});

哪个更短更干净.我觉得我只是为了它而遵循 Ext.dispatch 模式.我的应用没有从状态的推送/弹出 url 历史记录中受益,这是我可以看到使用这种更长更复杂的方法的唯一原因.

Which is shorter and cleaner. I feel like I am just following the Ext.dispatch pattern for the sake of it. My app doesn't benefit from push/pop url history for state, and that is the only reason I can see for using this longer more complex approach.

我错过了什么?使用 Ext.dispatch 调用控制器有什么好处?

What am I missing? What do I gain from using Ext.dispatch to call controllers?

推荐答案

beforedispatch 事件在您需要将它们重定向到另一个控制器时非常方便.

The beforedispatch event is handy in case you need to redirect them to another controller.

使用 dispatch 还可以让我根据需要加载控制器代码,而不是在页面加载时一次性加载.我以这种方式将应用的启动时间缩短了一半.

Using dispatch also lets me load the controller code as needed instead of all at once on page load. I cut my app's startup time in half that way.

您说您的应用不需要它,但我认为能够设置 historyUrl 并直接链接到页面将是其他用户的主要好处.

You said your app didn't need it, but being able to set the historyUrl and directly link to pages would be the main benefit for other users I think.

所以我想这完全取决于应用程序是否有意义.

So I guess it all depends on the app whether it makes sense to use it.

这篇关于为什么我应该使用 Ext.dispatch 而不是直接调用控制器代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆