Commit 1527f4a9 authored by Tristan Cavelier's avatar Tristan Cavelier

jslint pass storage.js

parent ac79eed3
var storage = function(spec, my) { /*jslint indent: 2, maxlen: 80, sloppy: true */
var that = {}; /*global command: true, jobManager: true, job: true */
var storage = function (spec, my) {
var that = {}, priv = {};
spec = spec || {}; spec = spec || {};
my = my || {}; my = my || {};
// Attributes // // Attributes //
var priv = {};
priv.type = spec.type || ''; priv.type = spec.type || '';
// Methods // // Methods //
Object.defineProperty(that,"getType",{ Object.defineProperty(that, "getType", {
configurable:false,enumerable:false,writable:false,value: configurable: false,
function() { enumerable: false,
writable: false,
value: function () {
return priv.type; return priv.type;
} }
}); });
...@@ -19,7 +22,7 @@ var storage = function(spec, my) { ...@@ -19,7 +22,7 @@ var storage = function(spec, my) {
* @method execute * @method execute
* @param {object} command The command * @param {object} command The command
*/ */
that.execute = function(command) { that.execute = function (command) {
that.success = command.success; that.success = command.success;
that.error = command.error; that.error = command.error;
that.retry = command.retry; that.retry = command.retry;
...@@ -34,7 +37,7 @@ var storage = function(spec, my) { ...@@ -34,7 +37,7 @@ var storage = function(spec, my) {
* @method isValid * @method isValid
* @return {boolean} true if ok, else false. * @return {boolean} true if ok, else false.
*/ */
that.isValid = function() { that.isValid = function () {
return true; return true;
}; };
...@@ -42,9 +45,11 @@ var storage = function(spec, my) { ...@@ -42,9 +45,11 @@ var storage = function(spec, my) {
var mess = that.validateState(); var mess = that.validateState();
if (mess) { if (mess) {
that.error({ that.error({
status:0,statusText:'Invalid Storage', "status": 0,
error:'invalid_storage', "statusText": "Invalid Storage",
message:mess,reason:mess "error": "invalid_storage",
"message": mess,
"reason": mess
}); });
return false; return false;
} }
...@@ -56,9 +61,9 @@ var storage = function(spec, my) { ...@@ -56,9 +61,9 @@ var storage = function(spec, my) {
* @method serialized * @method serialized
* @return {object} The serialized storage. * @return {object} The serialized storage.
*/ */
that.serialized = function() { that.serialized = function () {
var o = that.specToStore() || {}; var o = that.specToStore() || {};
o["type"] = that.getType(); o.type = that.getType();
return o; return o;
}; };
...@@ -78,7 +83,7 @@ var storage = function(spec, my) { ...@@ -78,7 +83,7 @@ var storage = function(spec, my) {
* @method validateState * @method validateState
* @return {string} empty: ok, else error message. * @return {string} empty: ok, else error message.
*/ */
that.validateState = function() { that.validateState = function () {
return ''; return '';
}; };
...@@ -154,24 +159,24 @@ var storage = function(spec, my) { ...@@ -154,24 +159,24 @@ var storage = function(spec, my) {
}); });
}; };
that.success = function() {}; that.success = function () {};
that.retry = function() {}; that.retry = function () {};
that.error = function() {}; that.error = function () {};
that.end = function() {}; // terminate the current job. that.end = function () {}; // terminate the current job.
priv.newCommand = function (method, spec) { priv.newCommand = function (method, spec) {
var o = spec || {}; var o = spec || {};
o.label = method; o.label = method;
return command (o, my); return command(o, my);
}; };
priv.storage = my.storage; priv.storage = my.storage;
delete my.storage; delete my.storage;
that.addJob = function (method,storage_spec,doc,option,success,error) { that.addJob = function (method, storage_spec, doc, option, success, error) {
var command_opt = { var command_opt = {
options: option, options: option,
callbacks:{success:success,error:error} callbacks: {success: success, error: error}
}; };
if (doc) { if (doc) {
if (method === 'get') { if (method === 'get') {
...@@ -180,12 +185,10 @@ var storage = function(spec, my) { ...@@ -180,12 +185,10 @@ var storage = function(spec, my) {
command_opt.doc = doc; command_opt.doc = doc;
} }
} }
jobManager.addJob ( jobManager.addJob(job({
job({ storage: priv.storage(storage_spec || {}),
storage:priv.storage(storage_spec||{}), command: priv.newCommand(method, command_opt)
command:priv.newCommand(method,command_opt) }, my));
}, my)
);
}; };
return that; return that;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment