Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot use getApplication() in a store or a view

I'm writing a simple Sencha Touch 2 Application with the new MVC Pattern of the Framework - so, there are models, stores, controllers and views and all is tied together with an Application.

Now, there is the possability to use "this.getApplication()" to get the instance of this super uber-class "Application".

And now there is the problem - getApplication() returns only the app-instance, if i'm in a controller - in a view, a model or a store, it is returning "undefined".

Basically, i can understand the idea behind this behavior - your business has to be in controllers, nowhere else.. and so you don't have to know the app-instance in stuff like stores, views or models...

Okey but.. it would be extremely nice to have global-properties living in the main-app.

For example, i want to define my webservice-url globally in the Application and use that variable everywhere i need to - and unfortunately, i need this url in a store too.

Now, the only way i see to access this global variable in a store is the way through my Namespace. Instead of using "this.getApplication().serviceUrl" i found only the solution through the namespace with "NameOfMyApp.app.serviceUrl" - and that could not be the best way to solve this.

Any ideas about that problematic? Is there a better, always working way to get the app instance from everywhere? Or, where should i store global variables if not in the Application?

like image 247
jebbie Avatar asked Feb 16 '12 18:02

jebbie


2 Answers

You can access the application instance on the AppName.app property in the latest Sencha Touch 2 betas.

Ext.application({
    name: 'Sencha',

    launch: function() {
        // Logs the application instance
        console.log(Sencha.app);
    }
});
like image 89
rdougan Avatar answered Sep 28 '22 23:09

rdougan


looks like Ext.app.Application.appInstance is app name agnostic solution

like image 30
olegtaranenko Avatar answered Sep 28 '22 21:09

olegtaranenko