Last active
July 16, 2019 07:18
-
-
Save Sarverott/6e3577ba27e45e68c88b9c567bb93adb to your computer and use it in GitHub Desktop.
simple sheme for core of software in js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Sett Sarverott | |
core-sheme.js | |
summer 2019 | |
*/ | |
class Core{ | |
constructor(opts={}){ | |
this.opts=this.defaults(opts); | |
this.init(); | |
if(this.opts.mode=="auto"){ | |
this.loop(); | |
}else if(this.opts.mode=="toolbox"){ | |
this.toolbox(); | |
}else if(this.opts.mode=="debug"){ | |
this.debug(); | |
}else{ | |
throw "unknow run mode"; | |
} | |
} | |
defaults(opts={}){ | |
var defaultsOpts={ | |
mode:"auto", | |
args:[], | |
settingsPath:null | |
} | |
if(!opts.hasOwnProperty("mode")){ | |
opts.mode=defaultsOpts.mode; | |
}else if(typeof(opts.mode)!="string"){ | |
opts.mode=defaultsOpts.mode; | |
} | |
if(!opts.hasOwnProperty("args")){ | |
opts.args=defaultsOpts.args; | |
}else if(!(opts.args instanceof Array)){ | |
if(opts.args.length!=0){ | |
opts.args=defaultsOpts.args; | |
} | |
} | |
if(!opts.hasOwnProperty("settingsPath")){ | |
opts.settingsPath=defaultsOpts.settingsPath; | |
}else if(typeof(opts.settingsPath)!="string"){ | |
opts.settingsPath=defaultsOpts.settingsPath; | |
} | |
return opts; | |
} | |
loop(repeat=true){ | |
if(repeat){ | |
repeat=this.loopContent(); | |
if(repeat===undefined||repeat===null){ | |
repeat=true; | |
} | |
this.loop(); | |
} | |
} | |
init(){ | |
this.setup(); | |
this.listeners(); | |
} | |
//BEGIN edits | |
setup(){ //first function, setup of core | |
} | |
listeners(){ //second function, set listeners here | |
} | |
//after setup and listeners, depends on mode | |
loopContent(){ //lunched on auto mode, looped if returning true | |
return true; | |
} | |
toolbox(){ //lunched on toolbox mode | |
} | |
debug(){ //lunched on debug mode | |
} | |
//END edits | |
} | |
/* | |
new Core({ | |
mode:"debug"/"toolbox"/"auto", //mode of lunch | |
args:[], //arguments, dedicated to commandline run | |
settingsPath:"" //path to settings file | |
}); | |
*/ | |
/* | |
class System extends Core{ | |
setup(){} | |
listeners(){} | |
loopContent(){} | |
toolbox(){} | |
debug(){} | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment