1

What is the difference between these Sencha Touch API functions.

Ext.getStore('myStore') and Ext.getStore('myStore').load()

I found at many places including sencha docs but could not find any appropriate answer.

Sarim Javaid Khan
  • 810
  • 15
  • 30

1 Answers1

3

Let's take a look at this:

var myStore = Ext.getStore( 'myStore' );
myStore.load();

Ext.getStore( id ) will search the StoreManager for a store with the provided id. If it finds one it will return it otherwise it will return null. If you have a store object you can load it via store.load(); That's a function of the store.

Only getting the store via getStore does not mean that the data is up to date. To assure it you have to load the store.

Update:

Let's assume you have a localstore. You have already stored some data in it. Now the user closes the app and restarts it. When your store is not set to autoLoad: true sencha will create the store object for you which you can access by var store = Ext.getStore( 'myLocalStore' ); This store object will NOT contain any data from the underlying localstorage. You have to load the store manually by store.load();. Now you can add some more data and sync it, so the underlying localstorage will get the new data.

Martin
  • 852
  • 7
  • 20
  • that means that by using load function we can get the updated data which has already been synced in the store? – Sarim Javaid Khan Jul 22 '14 at 13:57
  • No. Syncing the store means making the changes persistent. – Martin Jul 22 '14 at 13:58
  • yeah exactly. I am asking something else. Let suppose I have made the changes persistent to my store. these changes I can get by using Ext.getStore(id).load() not just by Ext.getStore(id) , isn't it? – Sarim Javaid Khan Jul 22 '14 at 14:00
  • I think its almost clear to me now. Thanks for the help. – Sarim Javaid Khan Jul 22 '14 at 14:08
  • This depends on the store type and the underlying proxy. When you add data to the store object it will normally contain all records you just added, you don't need to sync the store and you also don't need to load the store. Loading the store is only necessary if there is a change that the records of the underlying store representation have changed. You will not get notified automatically on such event. So if you suspect such change you should load the store and then add your records. – Martin Jul 22 '14 at 14:09