1. #1
    Sencha Premium Member
    Join Date
    Nov 2010
    Posts
    31
    Vote Rating
    4
    Alexey.Solonets is on a distinguished road

      1  

    Default [4.2.0] Ext.data.Store removeAll() destroys records instead of clearing data

    [4.2.0] Ext.data.Store removeAll() destroys records instead of clearing data


    Hi guys. I tried to test new ExtJs 4.2.0 version and I'm shocked a bit.

    Previously Ext.data.Store removeAll() method just cleared it's data:

    Code:
    removeAll: function(silent) {
        var me = this;
    
    
        me.clearData();
        if (me.snapshot) {
            me.snapshot.clear();
        }
        if (silent !== true) {
            me.fireEvent('clear', me);
        }
    }
    But now it physically removes all records from the server:
    Code:
    removeAll: function(silent) {
        var me = this;
    
    
        // Use the remove range interface to remove the entire record set, passing the silent flag.
        // The remove range interface does not fire individual remove events.
        me.remove({
            start: 0,
            end: me.getCount() - 1
        }, false, silent);
    
    
        // Special handling to synch the PageMap only for removeAll
        // TODO: handle other store/data modifications WRT buffered Stores.
        if (me.data) {
            me.data.clear();
        }
        if (silent !== true) {
            me.fireEvent('clear', me);
        }
    }
    Since no documentation were updated (`Individual record remove events are not fired by this method`), I think it is a bug.

    I suppose some bugfixes like this could cause such side-effect.

    So my questions are:
    1. Is it a bug? (dangerous bug, because I lost my data while testing new version)
    2. How can I just clear store with no physical data removing?

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,642
    Vote Rating
    899
    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

      -1  

    Default


    It removes it from the server meaning that it sends a sync request to the server when you remove them all? This should only happen if you execute sync() on the store or if you have autoSync set to true on the store.
    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 Premium Member
    Join Date
    Nov 2010
    Posts
    31
    Vote Rating
    4
    Alexey.Solonets is on a distinguished road

      1  

    Default


    Hi Mitchell,

    Yes autoSync is set to true. The problem is in the removeAll method. In ExtJs 4.1 it was meant as clear. Even method's documentation proved it (Individual record remove events are not fired by this method). Now in 4.2 removeAll means truly remove. But neither documentation was changed nor any warning messages was made in release notes.

    I made two demos in JsFiddle. Code is identical. Resources are different. Check this out:
    ExtJs 4.1 http://jsfiddle.net/u5FZA/
    ExtJs 4.2 http://jsfiddle.net/NKTY9/

    Steps to reproduce the problem:
    1. Select 'North America'
    2. Select 'Canada'
    3. Remember 2 city names
    4. Select 'South America'
    5. Select 'North America' again
    6. Select 'Canada' again
    7. Cities will remain same in ExtJs 4.1 and will be destroyed in 4.2.

  4. #4
    Sencha Premium Member
    Join Date
    Nov 2010
    Posts
    31
    Vote Rating
    4
    Alexey.Solonets is on a distinguished road

      1  

    Default bump

    bump


    Guys (developers), I can't understand why there is no interest to my question. I'm just trying to warn you that I found the problem that can hurt others. Maybe my explanation is not clear...

    Again:
    I expect for removeAll() to clear store so that it don't send destroy commands to the server. Even if I call sync() method after that. I use this method in master-detail grids and I'm sure others do the same. Everything was fine in ExtJs 4.0 and 4.1. But in 4.2 behavior changed with no warnings. Now removeAll() truly removes all records. "Truly" means that records are destroyed on the server. I repeat: there were no warnings about this behavior change.

    Or maybe I panic for nothing?

  5. #5
    Sencha Premium Member christoph.hartmann's Avatar
    Join Date
    Feb 2013
    Location
    Bonn, Germany
    Posts
    8
    Vote Rating
    1
    christoph.hartmann is on a distinguished road

      0  

    Default


    +1

    I am also interrested in a fix or workaround, I used removeAll() to clear a BUFFERED store in Ext Js 4.1 (but I did not sync).

  6. #6
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    Raleigh, NC
    Posts
    445
    Vote Rating
    272
    brian428 has much to be proud of brian428 has much to be proud of brian428 has much to be proud of brian428 has much to be proud of brian428 has much to be proud of brian428 has much to be proud of brian428 has much to be proud of brian428 has much to be proud of brian428 has much to be proud of

      1  

    Default


    First, you'll want to set autoSync to false. I always do this anyway, since I want to control what happens and use Deferreds to properly handle any asynchronous calls. I don't want async calls just blindly firing without proper success/failure handling.

    After that, you should just be able to call removeAll() and then immediately call commitChanges(), which clears any pending add, changed, and removed records.

  7. #7
    Sencha User
    Join Date
    Feb 2014
    Location
    Quezon City, Philippines
    Posts
    97
    Vote Rating
    3
    arnoldvillasanta is on a distinguished road

      0  

    Default Summary of Solution

    Summary of Solution


    Thanks for this thread...
    Here is the final code that works in my usecase (4.2.x)


    Code:
    Ext.getStore('StoreID').removeAll(true);
    Ext.getStore('StoreID').commitChanges(true);
    Ext.getCmp('GridID').view.refresh();
    My suggestion (to Sencha)
    1. Create a new method rather than having a SILENT parameter... Something more intuitive like others suggest
      • Ex.: Ext.getStore('StoreID').clearRecord();
    2. Combine the above 3 codes into 1 method having 2 parameters:
      • Ex.: Ext.getStore('StoreID').clearRecord(boolean, object)
        • param 1: commitChanges ---- finalize deletion of records in the local store
        • param 2: componentID ---- the component to be reset.