Success! Looks like we've fixed this one. According to our records the fix was applied for TOUCH-2682 in a recent build.
  1. #1
    Sencha User
    Join Date
    Jan 2008
    Location
    Toronto, Canada
    Posts
    480
    Vote Rating
    4
    elishnevsky is on a distinguished road

      0  

    Default [2.0.1 RC] Ext.util.Collection.clear() method does not clear indices.

    [2.0.1 RC] Ext.util.Collection.clear() method does not clear indices.


    It took me almost two hours to track down this one. I'm attaching a test case file for it, see below.

    STEPS:
    1. Create a simple in-memory store (you can define a model for it or just set its fields config, it doesn't matter).
    2. Create a List and set its store config to the store created in step 1.
    3. Call setData method of the store and pass an array with ONE object (that matches the model of course).
    4. Call removeAll method of the store to clear it.
    5. Call setData method again, but this time pass an array of more than one object that CONTAINS the object from step 3.

    EXPECTED RESULT:
    All the records are added to the store.

    ACTUAL RESULT:
    The store will only contain the record added in step 3, but not the other records. No exceptions are thrown though.

    DEBUGGING ALREADY DONE:
    First I compared Store.js file with the one from Sencha Touch v2.0.0 and notices that the insert method was changed. After debugging it I found that the data.indexOf() (Store.js line 917) still returns me a positive index although I called removeAll, so the data is supposed to be completely empty. Further debugging led me to the clear method in Ext.util.Collection class and I found that all the internal arrays are cleared but not the indices object, which is used in indexOf method.

    To fix the problem all I did was added one line to the clear method of Ext.util.Collection class:
    PHP Code:
    clear: function(){
        var 
    me this;

        
    me.length 0;
        
    me.items.length 0;
        
    me.keys.length 0;
        
    me.indices = {}; // <-- THE FIX
        
    me.all.length 0;
        
    me.map = {};

    ADDITIONAL NOTES:
    Collection.js files are identical between ST v2.0.0 and v2.0.1RC, which means this is not a new bug. The reason it came out now is because in 2.0.1RC you modified the insert method in Store.js where you now call to data.indexOf() which returns wrong result.

    This bug occurs after you add ONLY ONE record to a completely empty store, never initialized before. In Store.js line 951 I saw this:
    PHP Code:
    if (ln === 1) {
        
    added data.insert(indexrecords[0]);
        if (
    added) {
            
    added = [added];
        }
    } else {
        
    added data.insertAll(indexrecords);

    I'm not sure exactly why you do not just always call insertAll even when there only one record, I tried and it solved the original problem too, although the real problem is that indices wasn't cleared. Nevertheless, I looked at the two methods - insert and insertAll of Ext.util.Collection - and found them to be very different, when I actually expected insertAll to call insert at some point. I find it a little strange, but I live it up to you to decide if these methods are written correctly. Just wanted to point it out.

    Thank you.
    Attached Files

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,327
    Vote Rating
    850
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Nice catch!
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Mar 2007
    Location
    Haarlem, Netherlands
    Posts
    1,243
    Vote Rating
    10
    TommyMaintz will become famous soon enough TommyMaintz will become famous soon enough

      0  

    Default


    Hi, this has been resolved in the next release. Thanks for the report!

    Best,
    Tommy

Thread Participants: 2