1. #1
    Ext JS Premium Member
    Join Date
    Oct 2010
    Posts
    81
    Vote Rating
    1
    rhamflett is on a distinguished road

      0  

    Default Unanswered: Questions about creating stores on demand

    Unanswered: Questions about creating stores on demand


    If you have a class defined with a config option like "store: Ext.create('myapp.store.mystore', {})", then the store is always created. This happens when the page loads, before I ever actually instantiate an instance of that class. To get round this I'm having to move the store's creation to the code that creates an instance of the class, passing it in as a config item. I also worked out that I can create the store in the class's initComponent() method and specify a storeId. This would register it with the StoreManager, allowing me to then remove it from the StoreManager in the class's destroy() method. I don't want to declare the store in my controller, as the store is only useful for the associated class, which may never get instantiated. So I have two questions.

    1) Is there a way to do something like "store: Ext.create('myapp.store.mystore', {})" in the class definition so that a new store will get created when I create an instance?

    2) If I add, say, a grid to a tab panel like this:
    Code:
    myTabPanel.add({
        id: 'myId',
        title: 'My Grid',
        xtype: 'myGridClassAlias',
        store: Ext.create('myapp.store.mystore', {})
    });
    will the store eventually get destroyed if the user closes that tab, or do I have to add it to the StoreManager and remove it in that class's destroy method?

    3) Does removing a store from the StoreManager actually destroy it or just remove it from the StoreManager's list of known stores?


    Thanks,
    Rob Hamflett

  2. #2
    Sencha - Services Team arthurakay's Avatar
    Join Date
    Sep 2008
    Location
    Antioch, IL
    Posts
    1,374
    Vote Rating
    37
    Answers
    61
    arthurakay is a jewel in the rough arthurakay is a jewel in the rough arthurakay is a jewel in the rough arthurakay is a jewel in the rough

      0  

    Default


    If you do this:

    PHP Code:
    Ext.define('FooBar', {
        
    extend 'Ext.grid.Panel',
        
    store Ext.create('app.stores.FooBar', {})
    }); 
    ...not only will your store be created when that file loads, but ALL instances of that class will share the same data store (at least by default). You're setting a default value for that class.

    A better way would be:

    PHP Code:
    Ext.define('FooBar', {
        
    extend 'Ext.grid.Panel',
        
        
    initComponent : function() {
            
    Ext.applyIf(this, {
                
    store Ext.create('app.stores.FooBar', {})
            });

            
    FooBar.superclass.initComponent.call(this);
        }
    }); 
    In that example, a UNIQUE store is created upon instantiation (unless a store has been assigned via the config).
    Arthur Kay
    Developer Relations Manager, Sencha Inc.

    Twitter | Sencha Chicago User Group

  3. #3
    Ext JS Premium Member
    Join Date
    Oct 2010
    Posts
    81
    Vote Rating
    1
    rhamflett is on a distinguished road

      0  

    Default


    Thanks for the info about defining the store in the class. Would the store created in your example be destroyed when the user closes the tab containing the panel? I read somewhere on the forums that the garbage collector will eventually get rid of it if there aren't any references to it anywhere, but I haven't found a way for actually confirming when a store is properly cleaned up.

Thread Participants: 1

Tags for this Thread