Success! Looks like we've fixed this one. According to our records the fix was applied for EXTGWT-3077 in 3.0.6.
  1. #1
    Sencha Premium Member
    Join Date
    Dec 2012
    Posts
    5
    Vote Rating
    0
    noahtalmadge is on a distinguished road

      0  

    Post ListStore remove(M model) does not update private data member "debugKeys"

    ListStore remove(M model) does not update private data member "debugKeys"


    Required Information

    Version(s) of Ext GWT
    3.0.5


    Virtual Machine
    No

    Description
    ListStore's method remove(M model) removes regardless of the being in allItems or visibleItems. BUT in the case of the model being in allItems only "debugKeys" is not updated causing false duplicate detection.

    Run mode
    Both

    Steps to reproduce the problem
    1. Create a liststore
    2. Create model
    3. Add model to liststore
    4. Filter the liststore to exclude model
    5. Call remove(model)
    6. Call add(model)

    Expected result
    I expect the remove method to always update the debugKeys so that the internal lists and debugKeys are in-sync.

    Actual result
    deubgKeys is not being updated causing a false duplicate detection error

    Test case
    /**
    * Entry point classes define <code>onModuleLoad()</code>.
    *
    */
    public class GXTSandBox implements EntryPoint
    {
    /**
    * This is the entry point method.
    *
    */
    public void onModuleLoad ()
    {
    ListStore<TestModel> store = new ListStore<TestModel>(
    new ModelKeyProvider<TestModel>()
    {
    public String getKey (TestModel item)
    {
    return item.getId();
    }
    });
    store.setEnableFilters(true);


    TestModel testModel = new TestModel("testModel");
    store.add(testModel);

    store.addFilter(new StoreFilter<TestModel>()
    {
    public boolean select (Store<TestModel> store, TestModel parent, TestModel item)
    {
    return !(item.getId().equals("testModel"));
    }
    });

    GWT.log(store.size() + "");

    store.remove(testModel);
    store.add(testModel);

    }
    }


    /**
    */
    class TestModel
    {
    /**
    */
    private String id;

    /**
    * Constructor
    *
    */
    public TestModel (String id)
    {
    this.id = id;
    }

    public String getId ()
    {
    return this.id;
    }
    }


    Possible fix
    ListStore.java:

    /**
    * Removes the given item, visible or not, from the store.
    *
    * @param model model to remove
    * @return true if item was removed
    */
    public boolean remove (M model)
    {
    if (null == remove(indexOf(model)))
    {
    boolean result = allItems.remove(model);

    if (result)
    {
    this.debugKeys.remove(this.getKeyProvider().getKey(model));
    }
    return result;
    }

    return true;
    }

  2. #2
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,717
    Vote Rating
    89
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    Thanks for the report. The thinking had been that ListStore.remove(M) doesn't need to update debugKeys, since the first thing it does is to call ListStore.remove(int) which *does* remove that key, but clearly that doesn't work when filtered, since invisible items don't report an index, so the item gets lost.

    I've filed this internally, and will update this thread when we have a fix tested and committed.

  3. #3
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,717
    Vote Rating
    89
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    Thanks once again for the report - this has been fixed in SVN and the nightly builds, and will be available in the next release. The fix turned out to be slightly simpler - just removing the items from debugKeys if the existing if block is executed. This means that the items were not removed from the visible items, so still need to be a) removed from debugKeys (if not null) and b) removed from allItems.

Thread Participants: 1