1. #1
    Sencha Premium Member
    Join Date
    Mar 2009
    Posts
    49
    Vote Rating
    -13
    Dhugal can only hope to improve

      0  

    Default Answered: Ext.application does not create App object/namespace

    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:

    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/#!...pp.Application

    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?

  2. 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:
    Code:
    Ext.application({
        name: 'App',
        ...
        launch: function(){
            var me = this;
            Ext.namespace(me.name);
            ...
        }
    })

  3. #2
    Sencha User
    Join Date
    Jan 2012
    Posts
    1,376
    Vote Rating
    112
    Answers
    347
    vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all

      0  

    Default

    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:
    Code:
    Ext.application({
        name: 'App',
        ...
        launch: function(){
            var me = this;
            Ext.namespace(me.name);
            ...
        }
    })

  4. #3
    Sencha Premium Member
    Join Date
    Mar 2009
    Posts
    49
    Vote Rating
    -13
    Dhugal can only hope to improve

      0  

    Default

    Great - thanks for the response vietits.

  5. #4
    Sencha User mysticav's Avatar
    Join Date
    Mar 2007
    Location
    Mexico
    Posts
    522
    Vote Rating
    45
    Answers
    4
    mysticav will become famous soon enough mysticav will become famous soon enough

      0  

    Default

    On 4.1.1a it is created, but MyApp.getApplication() method does not exist.

    Why ?

  6. #5
    Sencha User
    Join Date
    Jan 2012
    Posts
    1,376
    Vote Rating
    112
    Answers
    347
    vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all

      0  

    Default

    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.
    Code:
    Ext.application({
        name: 'App',
        appFolder: 'app',
        launch: function() {
            console.log(App); // this will cause error "Uncaught ReferenceError: App is not defined"
        }
    });

Thread Participants: 2

Tags for this Thread