PDA

View Full Version : ExtJS singletons



xjscrafter
5 Feb 2014, 11:37 PM
I have a singleton class, and as a test I am calling a method of it in app.js launch() function, but the singleton static method is not defined:


Ext.Loader.setConfig({
enabled : true,
paths: {
'AM': 'app'
}
});


Ext.application({
name: 'AM',
autoCreateViewport: true,


requires: [
'AM.localization.ResourceManager'
],


controllers: [
'Users'
],


launch: function() {
alert(ResourceManager.initBundleLoader());
}
});


Ext.define('AM.localization.ResourceManager', {
alternateClassName: 'ResourceManager',
singleton: true,


init: function() {
this.initBundleLoader();
},


statics: {
test: 'here',
initBundleLoader: function() {
debugger;
Ext.applyIf(Ext.Loader, {
resourceBundles: new Object()
});
},


registerBundle: function(bundleName, locale) {
debugger;
if(!Ext.Loader.hasOwnProperty('resourceBundles')) {
this.initBundleLoader();
}
if(!Ext.Loader.resourceBundles.hasOwnProperty(bundleName)) {
if(Ext.ClassManager.isCreated('AM.locale.' + locale + '.resources.' + bundleName)) {
this.resourceBundles.bundleName = Ext.create('AM.locale.' + locale + '.resources.' + bundleName);
}
}
}
}
});

saJoshua
6 Feb 2014, 12:19 AM
Please provide a full drop in code sample to reference your question.

skirtle
6 Feb 2014, 2:42 AM
If it's a singleton then why bother wrapping them in a statics block?

xjscrafter
6 Feb 2014, 7:09 AM
I haven't used singletons a lot. When I remove the function from the statics, and just call it like this, still undefined:


launch: function() {
alert(ResourceManager.initBundleLoader());
}

xjscrafter
6 Feb 2014, 9:46 AM
Its because I wasn't returning anything from the method. Duh...Thanks for your help.