Results 1 to 3 of 3

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

    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
    Toronto, Canada
    Vote Rating

    Default [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.

    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.

    All the records are added to the store.

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

    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(){
    me this;

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

    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 Attached Files

  2. #2
    Sencha User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Gainesville, FL
    Vote Rating


    Nice catch!
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:

  3. #3
    Sencha User
    Join Date
    Mar 2007
    Haarlem, Netherlands
    Vote Rating


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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts