Reputation: 2332
I want to load some application specific settings and save them as global variables when the application is loaded. I have found how to create and access global variable here.
This is how my app.js
looks like:
Ext.application({
stores: [
...
],
views: [
...
],
autoCreateViewport: true,
name: 'MyApp',
controllers: [
'DefaultController'
],
launch: function() {
...
}
});
Is it possible to set these variables inside launch: function()
block? If not, are there any alternatives?
Upvotes: 3
Views: 5846
Reputation: 4421
You can also create a singleton:
Ext.define('MyApp.util.Utilities', {
singleton: true,
myGlobal: 1
});
in your app:
Ext.application({
stores: [
...
],
views: [
...
],
autoCreateViewport: true,
name: 'MyApp',
controllers: [
'DefaultController'
],
requires: ['MyApp.util.Utilities'], //Don't forget to require your class
launch: function() {
MyApp.util.Utilities.myGlobal = 2; //variables in singleton are auto static.
}
});
Upvotes: 6