Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 564
Chris Farmiloe Avatar asked May 29 '11 15:05

Chris Farmiloe


1 Answers

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.

like image 63
Jason Freitas Avatar answered Nov 11 '22 10:11

Jason Freitas