PDA

View Full Version : Ext.application does not create App object/namespace



Dhugal
27 Sep 2012, 3:41 AM
Hi All,

I am creating a new project using Ext 4.1 and attempting to use the MVC architecture however I have hit an issue in that the behaviour I am getting does not match the documentation.

Specifically I am using the following code:



Ext.application({
name: 'MyApp',
appFolder: 'Scripts/App',
launch: function () {
alert(MyApp);
}
});


The code throws an error on the alert call because MyApp has not been created. I have also tried this outside of the launch function (in Chromes console) and the object has not been created after the Ext.application has finished initialising.

What I am expecting is the call to Ext.application to create a global variable, in this case named "MyApp", as detailed in the documentation here:

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.app.Application
(http://docs.sencha.com/ext-js/4-0/#/guide/application_architecture)
Which when referring to this method states:

This does several things. First it creates a global variable called 'MyApp' - all of your Application's classes (such as its Models, Views and Controllers) will reside under this single namespace, which drastically lowers the chances of colliding global variables.

So I should subsequently be able to use code as follows to address the application elsewhere:

MyApp.getApplication()

So right now I am stuck because I don't have any way to address the application object.

Can anyone point out what's going on here please?

vietits
27 Sep 2012, 5:34 AM
It seems that Ext.application will only create application namespace if it has to load at least one application class, such as a controller (by using controllers config), viewport (with autoCreateViewport set to true), or a normal class with requires config.
My solution is explicitly create application namespace:


Ext.application({
name: 'App',
...
launch: function(){
var me = this;
Ext.namespace(me.name);
...
}
})

Dhugal
5 Oct 2012, 2:47 AM
Great - thanks for the response vietits.

mysticav
7 Nov 2012, 10:23 PM
On 4.1.1a it is created, but MyApp.getApplication() method does not exist.

Why ?

vietits
7 Nov 2012, 11:45 PM
No, with 4.1.1a, the situtation is still the same. It won't create application namespace if it won't have to load any application class.


Ext.application({
name: 'App',
appFolder: 'app',
launch: function() {
console.log(App); // this will cause error "Uncaught ReferenceError: App is not defined"
}
});