开发者

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

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜