Why should I use Ext.dispatch rather than calling controller code directly?

本小妞迷上赌 提交于 2019-12-09 16:28:41

问题


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
});

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.

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


回答1:


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

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.

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.



来源:https://stackoverflow.com/questions/6168561/why-should-i-use-ext-dispatch-rather-than-calling-controller-code-directly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!