1. #1
    Ext JS Premium Member
    Join Date
    Dec 2010
    Location
    Hamburg, Germany
    Posts
    193
    Vote Rating
    7
    winkelmann will become famous soon enough

      0  

    Default Ext.Direct and create multiple datasets in store

    Ext.Direct and create multiple datasets in store


    It seems a bit complex, but I will try to explain my problem anyway :-)

    * I have a store with autoSync:false and an Ext.Direct api defined for create:
    Code:
    api: {
       create: 'MyApp_DataProvider.create'
    }
    * I then add two datasets to the store
    * I then call store.sync()

    What I expect Ext.Direct to do, is call my api.create() function twice. What it DOES do, is call it once, but group the parameters together. Is that desired behavior or is it a bug?

    What it does:
    Code:
    {"action":"MyApp_DataProvider","method":"create","data":[[{"entity_id":0,"field1":"Content"},{"entity_id":0,"field1":"content2"}]],"type":"rpc","tid":1}
    Which means that it actually builds an array of parameter. I guess what the server is supposed to do is loop over the parameter lists and call the respective method twice?
    That would be OK afaik if it was the same structure for single-call requests, which it is not. Single-call requests look like this:
    Code:
    {"action":"MyApp_DataProvider","method":"create","data":[{"entity_id":0,"field1":"Content"}],"type":"rpc","tid":1}
    Which leaves me with no proper way to detect if it's actually a single-call or multi-call request.

    I hope someone gets what my problem is. What would be great, is a fixed structure for the request, not changing depending on the number of calls made to the same method.

  2. #2
    Ext JS Premium Member
    Join Date
    Dec 2010
    Location
    Hamburg, Germany
    Posts
    193
    Vote Rating
    7
    winkelmann will become famous soon enough

      0  

    Default


    So, today I am back at the office and I continued stepping through the ExtJS sources.
    It seems the problem isn't in Ext.Direct itself, but somewhere in the proxy logic between stores and Ext.Direct. I will continue stepping through the code.
    Until now, I was unable to figure out where the records are actually pushed to the proxy.

  3. #3
    Ext JS Premium Member
    Join Date
    Dec 2010
    Location
    Hamburg, Germany
    Posts
    193
    Vote Rating
    7
    winkelmann will become famous soon enough

      1  

    Default


    Finally figured it out. Quicker than I thought :-)

    The problem is the config allowSingle that, if true, allows the writer to write a single record without first wrapping it in an array, causing the different POST data structures.
    This makes it really really hard on the server side to implement a generic Ext.Direct API, since there is no way to differentiate between a single or a multi-call request, especially for store sync.
    My bug fix for now, is an override for Ext.data.proxy.Direct looking like this:

    Code:
    Ext.define('MyApp.overrides.data.proxy.Direct', {
        override: 'Ext.data.proxy.Direct',
    
        // Override writer config to disallow single per default
        writer: {
            type: 'json',
            allowSingle: false
        }
    });
    Another option would be to specify a custom writer for each model/store you have. But I think the override is a more elegant solution here.

    My question to the Sencha Devs is: What's your take on it? Should this maybe be changed for the next version?

  4. #4
    Ext JS Premium Member
    Join Date
    Dec 2010
    Location
    Hamburg, Germany
    Posts
    193
    Vote Rating
    7
    winkelmann will become famous soon enough

      1  

    Default


    I have added another override that will force argument lists to always be passed as an array, so we always have the same structure when requesting data:

    Code:
    Ext.define('MyApp.overrides.direct.RemotingMethod', {
        override: 'Ext.direct.RemotingMethod',
    
        getArgs: function(params, paramOrder, paramsAsHash) {
            return [this.callParent(arguments)];
        }
    });
    This should finally force all argument lists (no matter if the Direct method was called once or multiple times) to be wrapped in an array at first level.

  5. #5
    Sencha - Support Team
    Join Date
    Feb 2013
    Location
    California
    Posts
    3,557
    Vote Rating
    66
    Gary Schlosberg is a jewel in the rough Gary Schlosberg is a jewel in the rough Gary Schlosberg is a jewel in the rough

      0  

    Default


    Great to hear that you got it resolved, and thanks for taking the time to follow up here.
    Get on the Fast Track with Sencha Training http://sencha.com/training

    Are you a Sencha products veteran who has wondered what it might be like to work at Sencha? If so, please reach out to our recruiting manager: sheryl@sencha.com

  6. #6
    Ext JS Premium Member
    Join Date
    Dec 2010
    Location
    Hamburg, Germany
    Posts
    193
    Vote Rating
    7
    winkelmann will become famous soon enough

      0  

    Default


    I'm sorry to disappoint you, but I still haven't got it resolved properly. I can properly differentiate between a single- and multi-call request now, but the problem still exists when manually calling Ext.Direct methods rather than letting the store/model handle it. I guess what I have to do is either implement data source handling (store/default) for direct transactions or intercept the data when it is actually set into jsonData.
    As soon as I get the data normalized properly, I will post my overrides here though.

Thread Participants: 1