dispatch而不是直接调用控制器代码

dispatch而不是直接调用控制器代码

本文介绍了为什么要使用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而不是直接调用控制器代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 19:21