View Full Version : Nested store load events - sometimes it stops working

2 Jun 2011, 6:09 AM
Hi guys,

I need to do a block of code before all my combos are loaded and i'm using this sample code:

store1.on('load', function(){

store2.on('load', function(){

store3.on('load', function(){
console.log('stores are loaded');
}, this)

}, this)

}, this);

This block of code is executed on afterrender on a window which is deleted on close action so all stores/events are recreated when another window is created.

Sometimes even if all the stores are loaded (i check in firebug for the response and i get it fine), the console.log function is not executed.

Am I doing something wrong? How should I execute a block of code after X stores are loaded?


2 Jun 2011, 11:00 AM
no one? is the method at least the proper way of doing this?

2 Jun 2011, 12:03 PM
I think you want to do this instead:

store1.on('load', function(){ store2.load(); }, this);
store2.on('load', function(){ store3.load(); }, this);
store3.on('load', function(){ console.log('stores are loaded'); }, this);

3 Jun 2011, 7:14 AM

Is there a possibility where i don't need to wait for the previous store to be loaded in order to trigger the next one to load?

Something similar to loading all stores and having an event that is triggered when all are loaded?

3 Jun 2011, 7:22 AM
Try this:

//remember the load event fires once the store is LOADED, not before it loads
//whichever store loads last will see the other 2 stores statuses as true
//the 1st and 2nd stores loaded will see the other stores statuses as false

store1.on('load', function(){ storesStatuses.Store1 = true; CheckStoreLoadProgress(); }, this);
store2.on('load', function(){ storesStatuses.Store2 = true; CheckStoreLoadProgress(); }, this);
store3.on('load', function(){ storesStatuses.Store3 = true; CheckStoreLoadProgress(); }, this);

var storesStatuses = { Store1: false, Store2: false, Store3:false };
function CheckStoreLoadProgress()
if(storesStatuses.Store1 && storesStatuses.Store2 && storeStatuses.Store3)
//do something

3 Jun 2011, 8:14 AM
true, that was exactly what i was thinking, make a function to check the loaded status of all stores and call it when each store is loaded.

thanks for your help