View Full Version : What do you think about registering modules to a global manager?

19 May 2010, 5:45 PM
Maybe ExtJS already has something for managing this but I don't know about it. :D
But basically I'm working on a uniform way to create my own modules custom widgets whatever you want to call them and register them with a global scope.
This will ensure that each module has its code encased and will not overwrite other code that someone else out there may throw into my app.
Module would get registered and can be retrieved.
Works just fine for me so far with 1/2 dozen or so modules.
But wanted to get some info from some of you more Experienced ExtJS people.

var modPath = 'modules/moduleName';
var modName = modPath + '/js/cnfg.js:';
fireBugLog(' =============== ');
fireBugLog(modName + ' Ext.onReady() executed.');

// Create our module Namespace
var NSTEST = function(){
this.date = "Mar 25, 2010";
this.category = "Messaging";
this.title = "Our test module";
this.image = modPath + "/media/graphics/image";
this.thumbImage = modPath + "media/graphics/thumbs";

this.getConfig = function(){
// all private vars
var myW = 290;
var myH = Ext.lib.Dom.getViewHeight() - 30;
var myX = Ext.lib.Dom.getViewWidth() - myW;
var myY = 0;
if(typeof(taskbarEl) == 'object'){
myH = Ext.lib.Dom.getViewHeight() - taskbarEl.getHeight();
fireBugLog('Exception:\n' + modName + '\ngetConfig(): ' + e.message);
} // try
} // if

return {
H:myH, W:myW, X:myX, Y:myY
}; // getConfig

return this;
}(); // NSTEST

// TODO Register the NameSpace of this module with the DASHBOARD if available
fireBugLog(modName + ' ---------------- start call to DASHBOARD -----------');
fireBugLog(modName + ' ---------------- end call to DASHBOARD -----------');
} // if
}) // Ext.onReady
To get the item that was registered all you need is to call it by name

var myMod = DASHBOARD.getModule('NSTEST');Then you can get at its methods/functions


20 May 2010, 5:43 AM
I am not too sure if Ext.namespace(), Ext.reg(), Ext.preg() already does this for you.

Anyways, just a thought.

20 May 2010, 6:12 AM
I am not too sure if Ext.namespace(), Ext.reg(), Ext.preg() already does this for you.
Anyways, just a thought.

I'll look into them. Thanks.

20 May 2010, 12:06 PM
Not sure how I ended up searching on OO stuff but I found this old post that may be helpful for others out there doing singletons
http://www.extjs.com/forum/showthread.php?26426-How-do-I-do-this-in-OO-Javascript Its a really good thread IMO.