PDA

View Full Version : How to I call Ext.application inside a callback?



rvelasquez
13 Apr 2012, 7:41 AM
I need to bootstrap Sencha after another system has completed initializing. I'm registering a callback function that executes after the other system has initialized. However when Ext.application is called nothing happens. I've put an alert in the launch method and nothing happens. Basically my app.js looks like this:



function otherSystemInitializedSuccess() {
alert('other system initialized');
Ext.application({
....


launch: function() {
alert('launch');
....
}
});
};


The initialization of the other system happens in body onLoad and I register the function otherSystemInitializedSuccess (which is defined in app.js) with it. I see the first alert but I never see the "launch" alert. Previously Ext.application call was not inside this method and was executed directly in the app.js file. I have to use the callback because Sencha depends on some stuff in the other system being ready.

mitchellsimoens
13 Apr 2012, 8:07 AM
The issue is the launch method of Ext.application will be delayed until the classes are loaded so you don't want to call Ext.application inside a function.

Instead you want to have some variable that is checked within the launch method and in your callback function fire the launch method checking to see if the variable should allow it to go.


var myvar = 0;

function otherSystemInitializedSuccess() {
Test.app.launch.call(Test);
}

Ext.application({
name : 'Test',

...

launch : function() {
if (myvar === 1) {
//continue here
}

myvar++;
}
});

You can see what I am describing right? I typed this without testing but just to describe what is going on.

rvelasquez
13 Apr 2012, 9:00 AM
Thanks, I understand your solution but I'm not sure I understand your explanation ...

"The issue is the launch method of Ext.application will be delayed until the classes are loaded so you don't want to call Ext.application inside a function."

Why does the delayed class loading affect the calling of the launch method when Ext.application is called inside another function?

Also I tried your implementation and it seems to be working but now it seems that some things are being loaded before they are ready. For example I have a controller that's dynamically creating a component and then adding it to a view. I'm getting errors now that indicate the view is not ready yet. Any ideas why that might be? Again when the app is loaded directly in app.js I don't have these problems.

Thanks again for you help.

mitchellsimoens
13 Apr 2012, 9:39 AM
Normally you would expect the launch method to fire when the document body is loaded but since we are loading classes that may happen after the document body says it is done loading, now the launch method is deferred until those classes are finished loading.