Ext.net.DirectMethod vs Ext.net.DirectEvent vs Ext.data.Connection vs Ext.Ajax

  1. #1

    Ext.net.DirectMethod vs Ext.net.DirectEvent vs Ext.data.Connection vs Ext.Ajax

    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...!/api/Ext.Ajax and http://docs.sencha.com/extjs/6.0/6.0....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.
    Last edited by RaphaelSaldanha; Apr 11, 2016 at 12:08 PM.
  2. #2
    Hello @Raphael!

    Thanks for the suggestion, we actually hoped our examples on Events (direct events // direct events, also available on MVC EE) 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?
    - Difference between DirectMethod , DirectEvent, Static DirectMethod

    Well, hope this helps you understand a little more about direct methods/events, although you already dug very deep on their actual codes!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. [CLOSED] Ext.data.Connection.setOptions(): No URL specified
    By matt in forum 3.x Legacy Premium Help
    Replies: 3
    Last Post: Jan 07, 2015, 7:53 PM
  2. Replies: 0
    Last Post: Feb 03, 2013, 1:40 AM
  3. Replies: 1
    Last Post: Jun 12, 2012, 10:34 AM
  4. [CLOSED] DirectEvent & DirectMethod
    By trieu.tran in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: May 31, 2012, 11:47 AM
  5. [CLOSED] Difference between DirectMethod , DirectEvent, Static DirectMethod
    By syllabusarq in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 01, 2011, 11:37 AM

Posting Permissions