Skip to content

Instantly share code, notes, and snippets.

@magcius
Created February 4, 2012 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magcius/f83deda903311d49edba to your computer and use it in GitHub Desktop.
Save magcius/f83deda903311d49edba to your computer and use it in GitHub Desktop.
// Base Module Class
function Module(){
this.id = "baseModule";
this.heading = "Base Module";
//Creates a module from the base class. arguments (moduleId and paramsObject{heading,heSig})
//Eg:baseModule.createModule("cm",{heading:"CM Module",heSig: cmHandleEvent});
this.createModule = function(id, obj){
var tmpModule = new Object();
tmpModule.id=id;
tmpModule.heading=obj.heading;
tmpModule.init=function(){
if (obj.heSig != null)
registerModule(this.id,obj.heSig);
}
tmpModule.handleEvent=function(){
logwr('warn',"handleEvent of Module : "+this.id+". This is an abstract method. It was not meant to be called for the derived class.");
}
tmpModule.raiseEvent=function(eve,params){
logwr('debug',"raised Event in "+this.id+" Event:"+eve);
// logwr('debug',"raised Event in "+this.id+" Event:"+eve+
// (params == null ? "" : " Params Received:"+params.length));
try{
raiseEvent(this.id,eve,params);
}catch(e){
logwr('error',"Exception while raising Event "+eve+" by "+this.id+" Ex:"+e);
}
}
return tmpModule;
}
}
//Factory method to get the base module class
function getBaseModule(){
if(Module != 'undefined'){
var bm = new Module();
return bm;
}
else{
alert("baseModule object is missing. Please make sure you include Module() class from baseModule.js");
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment