You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But on my Config class it does not give an extend method for some weird reason so I can't extend my JsonConfig class that is suppose to be abstract.
define(["observer/_subject","node.class"],function(Subject,Class){varfs=require('fs');varfile_path_validator=function(file_path){varis_ok=true;try{fs.accessSync(file_path,fs.F_OK);}catch(err){is_ok=false;}returnis_ok;};returnClass.extend({events: {/** * When config starts loading */onLoad: 1,/** * When json will be parsed and saved as data */onLoaded: 2,/** * When config contents change */onContentChange: 3},init: function(file_path){this.error=null;this.file_path=null;this.file_path_validator=null;/** * Stores data as a string before saving the to file or before parsing them into data * @type {String} */this.Contents=null;/** * Config data * @type {*} */this.data={};/** * Observer collection * @type Subject */this.Subject=null;this.setFilePath(file_path);this.setFilePathValidator(file_path_validator);this.setSubject(newSubject());},/** * Loads configuration file. Returns 1 on success -1 if file * didn't passed validation and -2 if error occurred while parsing its contents to JSON. * Calls 3 events on different occasions * @returns {*} */loadSync: function(){this.setError(null);varfile_path=this.getFilePath(),Subject=this.getSubject(),validator=this.getFilePathValidator();Subject.notify(this.events.onLoad,this);// validate pathif(validator(file_path)){this.setContents(fs.readFileSync(file_path,"utf8"));Subject.notify(this.events.onContentChange,this);try{this.setData(JSON.parse(this.getContents()));}catch(err){this.setError(err);return-2;}Subject.notify(this.events.onLoaded,this);return1;}else{return-1;}},/** * Returns data from loaded configuration file or def value if it does not exists * @param id * @param def * @returns {*|boolean} */get: function(id,def){returnthis.data[id]||(def||false);},getContents: function(){returnthis.Contents;},getData: function(){returnthis.data;},getError: function(){returnthis.error;},getFilePath: function(){returnthis.file_path;},getFilePathValidator: function(){returnthis.file_path_validator;},getSubject: function(){returnthis.Subject;},set: function(id,value){this.data[id]=value;},setContents: function(Contents){this.Contents=Contents;},setData: function(data){this.data=data;},setError: function(error){this.error=error;},setFilePath: function(file_path){this.file_path=file_path;},setFilePathValidator: function(validator){this.file_path_validator=validator;},setSubject: function(Subject){this.Subject=Subject;}});});
The text was updated successfully, but these errors were encountered:
@tarach Is the code frontend or backend? Your example confused me a bit since this define(["observer/_subject", "node.class"], function(Subject, Class) part looks like frontend code but this var fs = require('fs'); looks like backend code.
It's a node webkit so you could say it's both. It's loaded via requirejs which means it's executed in webkit context but require('fs') executes in node context.
For some reason child class has no extend() method.
I wrote small test and it works like a charm:
But on my Config class it does not give an extend method for some weird reason so I can't extend my JsonConfig class that is suppose to be abstract.
The text was updated successfully, but these errors were encountered: