1. #1
    Sencha User
    Join Date
    Jun 2011
    Location
    Ukraine, Mykolayiv
    Posts
    101
    Vote Rating
    1
    rsqw is on a distinguished road

      0  

    Default destroying associated-store

    Hi,

    How can I completely destroy the associated store?

    My solution is:
    Code:
    user.posts().destroyStore();
    delete user.postsStore;
    Does anybody know the best solution for this?

    Thanks

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,263
    Vote Rating
    486
    scottmartin has a reputation beyond repute scottmartin has a reputation beyond repute scottmartin has a reputation beyond repute scottmartin has a reputation beyond repute scottmartin has a reputation beyond repute scottmartin has a reputation beyond repute scottmartin has a reputation beyond repute scottmartin has a reputation beyond repute scottmartin has a reputation beyond repute scottmartin has a reputation beyond repute scottmartin has a reputation beyond repute

      0  

    Default

    The private function destroyStore() in 4.x should do what you need. This basically the same as store.destroy() in 3.4.

    As long as you remove all reference to your store (StoreManager, components) then it should be picked up the garbage collector.

    Regards,
    Scott.

  3. #3
    Sencha User
    Join Date
    Jun 2011
    Location
    Ukraine, Mykolayiv
    Posts
    101
    Vote Rating
    1
    rsqw is on a distinguished road

      0  

    Default

    The private function destroyStore() in 4.x should do what you need --- unfortunately, no

    in my case after user.posts().destroyStore(), user.postsStore still exists

  4. #4
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,263
    Vote Rating
    486
    scottmartin has a reputation beyond repute scottmartin has a reputation beyond repute scottmartin has a reputation beyond repute scottmartin has a reputation beyond repute scottmartin has a reputation beyond repute scottmartin has a reputation beyond repute scottmartin has a reputation beyond repute scottmartin has a reputation beyond repute scottmartin has a reputation beyond repute scottmartin has a reputation beyond repute scottmartin has a reputation beyond repute

      0  

    Default

    I am not sure I understand your call...

    mystore.destroyStore() does not work?

    Scott.

  5. #5
    Sencha User
    Join Date
    Jun 2011
    Location
    Ukraine, Mykolayiv
    Posts
    101
    Vote Rating
    1
    rsqw is on a distinguished road

      0  

    Default

    Ok, I'll try to make things clear.
    Code:
    Ext.define("Website", {
        extend: "Ext.data.Model",
        idProperty: "websiteId",
        fields: [
            'websiteId', 
            'website', 
            'active'
        ],
        proxy: {
            type: 'ajax',
            reader: {
                type: "json",
                root: "items"
            }
        }
    });
    
    Ext.define("User", {
        extend: "Ext.data.Model",
        idProperty: "userId",
        fields: [
            'firstName', 
            'lastName'
        ],
        associations: [{
            type: "hasMany",
            name: "websites",
            model: "Website",
            primaryKey: "userId",
            foreignKey: "userId",
            storeConfig: {
                storeId: "websites"
            }
        }],
        proxy: {
            type: "memory",
            reader: {
                root: "items",
                type: "json"
            }
        }
    });
    
    
    Ext.define("Users", {
        extend: "Ext.data.Store",
        model: "User",
        data: {
            items: [{
                firstName: "F1",
                lastName: "L1",
                userId: 1,
                websites: [{
                    websiteId: 1,
                    userId: 1,
                    website: "http://facebook.com/rsqw",
                    active: 1
                }, {
                    websiteId: 2,
                    userId: 1,
                    website: "http://twitter.com/rsqw",
                    active: 1
                }]
            }]
        },
        autoLoad: true
    });
    now, type in your console these lines:
    store = new Users;
    store.first().websites().destroyStore();

    so, as far as I understand, websites-store should be picked up the garbage collector, Yes?

  6. #6
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,773
    Vote Rating
    372
    skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute

      0  

    Default

    No. Calling destroyStore will just tear down the internals of the store. It can't remove all references to it to make it eligible for garbage collection. If the only reference to the store is from the owner record then it will become eligible for garbage collection at the same time as the record.

    Perhaps a better question is why are you trying to destroy an associated store? There are some cases where it makes sense but I'd be curious to know what your motivation is.

Thread Participants: 2