1. #1
    Sencha - Dev Team
    Join Date
    Aug 2012
    Location
    France
    Posts
    23
    Vote Rating
    0
    NiNiX is on a distinguished road

      0  

    Default [0.7.10] remote records are not properly imported into stores

    [0.7.10] remote records are not properly imported into stores


    Versions: 0.7.10 (and 0.7.8) with Sencha Touch 2.1.1
    Browser: Chrome 24 (Win8 / Desktop)
    Severity: normal
    Attachment: 0.7.10 patch proposal

    When a record receives a new global ID (e.g. id: 2 (local) -> id: b9-67779170 (remote)), store filters, groupers and sorters are not correctly applied, which can lead to inconsistencies in views. For instance, the record will not be sorted in the list, grouped lists will not display the group header on the correct item or a record which no longer matches filters will stay displayed in list instead to be removed. These artifacts will disappear - for faulty records - after an app reboot.

    Test case

    I used the 'examples/touch/todo' example without modification (note that it's one test case among many other).

    - Create 3 tasks with titles: "A", "B" and "C" (the list now contains 3 items in this order: C, B, A)
    - Edit C, change "completed" to true and save: C is now strikeout but remains at the first position
    - Edit A, change "completed" to true and save: A is now strikeout at the last position

    Expected order would be: B, A then C (and not C, B, A), because the 'todos' store defines the following sorters:
    PHP Code:
    [...]
        
    sorters: [
            {
               
    property 'completed',
               
    direction'ASC'
            
    },
            {
               
    property 'timestamp',
               
    direction'DESC'
            
    }
        ]
    [...] 
    - Relaunch the app: the list is correctly ordered.

    Debug

    Two reasons can explain this issue: first, you silently change the record local id to its new oid in the create method (cf/data/SyncProxy.js). By doing that, objects which maintain an internal map based on this record id will not be notified about id modification (which is exactly the case for group in stores). I fixed it by using record.set() despite the developer comment. I don't known side effects about using this method, or if it was just an optimization but it fixed lot of issues in my project.
    PHP Code:
    [...]
        
    // the user id is the oid.
       //record.data[this.idProperty]= record.getOid(); // warning: don't call record.set, it'll cause an update after the add

        // FIX: above message warns about not calling record.set, but
        // record ID related notifications should be performed in order
        // to update existing ID mapping (for instance store internal
        // data indices used by grouped lists).
        
    record.set(this.idPropertyrecord.getOid());
    [...] 
    The second reason is that imported records are not joined to the store, but directly added to its internal data. It takes place in the updateStore method (io/data/Proxy.js). I fixed this by explicitly joining records to the updated store:
    PHP Code:
    [...]
        
    updateStore: function(store,createdRecords,updatedRecords,removedRecords){
            var 
    changed false;
            var 
    li;
            if(
    createdRecords && createdRecords.length>0) {
                
    store.data.addAll(createdRecords);

                
    // FIX: we need to join the store for created records in
                // order to have store notifications on record updates.
                
    Ext.each(createdRecords, function(record) {
                    
    record.join(store);
                });

                
    store.fireEvent('addrecords'thiscreatedRecords0);
                
    changed true;
            }
            if(
    updatedRecords && updatedRecords.length>0) {
                
    store.data.addAll(updatedRecords);

                
    // FIX: we need to join the store for updated records in
                // order to have store notifications on record updates.
                
    Ext.each(updatedRecords, function(record) {
                    
    record.join(store);
                });
    [...] 
    I attached the full patch over 0.7.10 used for my project.
    Attached Files

  2. #2
    Sencha - IO Dev Team
    Join Date
    Apr 2011
    Posts
    85
    Vote Rating
    5
    jason.cline is on a distinguished road

      0  

    Default


    0.7.13 should resolve these issues.


    Thank you again for your help



  3. #3
    Sencha - Dev Team
    Join Date
    Aug 2012
    Location
    France
    Posts
    23
    Vote Rating
    0
    NiNiX is on a distinguished road

      0  

    Default


    Upgraded my project to version 0.7.13, and I confirm that this issue is fixed

    Thanks

Thread Participants: 1

Tags for this Thread