View Full Version : Ext.net.DirectMethod vs Ext.net.DirectEvent vs Ext.data.Connection vs Ext.Ajax

Apr 08, 2016, 2:44 PM
For many years i've been using Ext.net.DirectMethod to send http requests to the application's server.

After reading the thread http://forums.ext.net/showthread.php?51091, open by @Anup, i decided it was time to have a deeper knowledge of Ext.net.DirectMethod.

I know that there are several ways to send http requests to the server, such: Ext.net.DirectMethod, Ext.net.DirectEvent, Ext.data.Connection and Ext.Ajax.

I can't remember why i decided to use Ext.net.DirectMethod and unfortunately i was not able to find any documentation directing the usage of those classes/components.

On core/direct/DirectMethod.js we have that Ext.net.DirectMethod internally uses Ext.net.DirectEvent

Ext.net.DirectMethod = {
request: function (name, options) {
return Ext.net.DirectEvent.request(Ext.apply(options, obj));

On core/direct/DirectEvent.js we have that Ext.net.DirectEvent is acctually Ext.data.Connection

Ext.net.DirectEvent = new Ext.data.Connection();

As if that was not enough, we have Ext.Ajax, that according to sencha is:

In general, this class will be used for all Ajax requests in your application.
The main reason for creating a separate {@link Ext.data.Connection} is for a
series of requests that share common settings that are different to all other
requests in the application.

Source:http://docs.sencha.com/extjs/6.0/6.0.2-classic/#!/api/Ext.Ajax and http://docs.sencha.com/extjs/6.0/6.0.2-classic/source/Ajax3.html#Ext-Ajax

It would be interesting that you provide some documentation, so we could decide the best component for each scenario.

Thanks in advance.

Apr 15, 2016, 12:26 AM
Hello @Raphael!

Thanks for the suggestion, we actually hoped our examples on Events (direct events (http://examples4.ext.net/#/Events/DirectEvents/Overview/) // direct events (http://examples4.ext.net/#/Events/DirectMethods/Overview/), also available on MVC EE (http://mvc4.ext.net/)) gave a good idea on where to use them, and which situation.

In fact, direct events are not so clearly different than direct methods in MVC environment as they are in WebForms, so it may get more confusing if you work only on MVC.

Basically the difference between them is that direct events are event-oriented, while direct methods try to mimic an ordinary method, with parameter and return value.

If you check the examples linked above, you'll see how parameters are encapsulated when we want to pass something to direct events. When we are working on direct methods, we but pass an argument to the "function". Direct methods also require attributes decoration and are exported into the .direct namespace (App.direct by default) to be easily called from the code.

On WebForms, DirectEvents are wired to ASPX event handlers, so that one can just bind a click DirectEvent with a OnDirectClick="myEventName" and it has a dedicated DirectEventArgs parameter instead of the usual EventArgs we see, for example, on the Page_Load() handler. That's essentially the part that changes from WebForms to MVC when you use the direct event to call an action. If you use the direct method to call an action as well, they will look pretty much the same (although it is not really true).

We may consider writing a blog post on the differences and when to use and when not to use those, thanks again for the suggestion!

As for already existing documentation, we actually have the forums. We have the premium forums open for everyone to read exactly because it can be used as a good source of information for users -- and in a central location. So you'll often find answers for your question when you give the forums a search. I personally like letting google search the forums with (for example) a pattern like: site:forums.ext.net differences directmethod directevent. This search gave me two good threads:
- DirectEvent or static DirectMethod? (http://forums.ext.net/showthread.php?11154)
- Difference between DirectMethod , DirectEvent, Static DirectMethod (http://forums.ext.net/showthread.php?12613)

Well, hope this helps you understand a little more about direct methods/events, although you already dug very deep on their actual codes!