PDA

View Full Version : Synchronous store load



nayak14
18 Sep 2009, 6:13 AM
I want to wait till the store load happens so i can process the records coming from it.
Is there any option to call synchronous store.load()?
how can i do that?

thanks

VinylFox
18 Sep 2009, 6:48 AM
The better question is 'why would you want to do that?'

Using an event (such as the 'load' event of a Store) or a callback is the standard method to get one action to wait for the other.

rlegend
18 Sep 2009, 10:36 AM
Callbacks are definitely the way to go. If you really need synchronous AJAX you might want to give the ext-basex extension a look.

http://www.extjs.com/forum/showthread.php?t=21681

nayak14
21 Sep 2009, 9:54 AM
don't we have option to specify sync:true/false in store proxy definition....???
sometimes we really need to process some records in sequence.


Regards,
Harshad

hendricd
21 Sep 2009, 10:38 AM
@nayak -- Although there are good use-cases (albeit not many) to use synchronous calls, your requirement does not need to 'hard-block' the browser for the sake of serial thinking.

Use a popular pattern that gets you what you want -- without all the penalties.
Give all your stores storeId's, then:



var storesToLoad = [
{store : 'statesStore', url : 'data/states.php, params : { ....} },
{store : 'clothingStore', url : 'data/clothing.php, params : { ....} },
{store : 'sizesStore', url : 'data/sizes.php, params : { ....} },
{store : 'inventoryStore', url : 'data/inv.php, method: 'GET', params : { ....} }
];
var doThisAfterAllStoresAreLoaded = App.buildLayout;

App.loadStartupStores = function(record, options, success){
var task = storesToLoad.shift(); //From the top
if(task){
if(success !== false){
task.callback = arguments.callee //let's do this again
var store = Ext.StoreMgr.lookup(task.store);
store ? store.load(task) : complain('bad store specified');
} else {
complain( );
}
} else {
doThisAfterAllStoresAreLoaded ();
}
};
App.loadStartupStores();