Commit c1c73f90 authored by Tristan Cavelier's avatar Tristan Cavelier

revisionstorage.js amd compatible now

parent e3d3b88f
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true */ /*jslint indent: 2, maxlen: 80, nomen: true */
/*global jIO: true, hex_sha256: true, setTimeout: true */ /*global jIO, hex_sha256, setTimeout, define */
/** /**
* JIO Revision Storage. * JIO Revision Storage.
* It manages document version and can generate conflicts. * It manages document version and can generate conflicts.
...@@ -9,8 +10,18 @@ ...@@ -9,8 +10,18 @@
* "sub_storage": <sub storage description> * "sub_storage": <sub storage description>
* } * }
*/ */
jIO.addStorageType("revision", function (spec, my) { // define([module_name], [dependencies], module);
(function (dependencies, module) {
"use strict";
if (typeof define === 'function' && define.amd) {
return define(dependencies, module);
}
module(jIO, hex_sha256);
}(['jio', 'sha256'], function (jIO, hex_sha256) {
"use strict"; "use strict";
jIO.addStorageType("revision", function (spec, my) {
var that = {}, priv = {}; var that = {}, priv = {};
spec = spec || {}; spec = spec || {};
that = my.basicStorage(spec, my); that = my.basicStorage(spec, my);
...@@ -106,7 +117,9 @@ jIO.addStorageType("revision", function (spec, my) { ...@@ -106,7 +117,9 @@ jIO.addStorageType("revision", function (spec, my) {
if (typeof doc._revs.start !== "number" || if (typeof doc._revs.start !== "number" ||
typeof doc._revs.ids !== "object" || typeof doc._revs.ids !== "object" ||
typeof doc._revs.ids.length !== "number") { typeof doc._revs.ids.length !== "number") {
return send_error("The document revision history is not well formated"); return send_error(
"The document revision history is not well formated"
);
} }
} }
if (typeof doc._revs_info === "object") { if (typeof doc._revs_info === "object") {
...@@ -320,7 +333,10 @@ jIO.addStorageType("revision", function (spec, my) { ...@@ -320,7 +333,10 @@ jIO.addStorageType("revision", function (spec, my) {
getWinnerRevsInfoRec = function (doc_tree, tmp_revs_info) { getWinnerRevsInfoRec = function (doc_tree, tmp_revs_info) {
var i; var i;
if (doc_tree.rev) { if (doc_tree.rev) {
tmp_revs_info.unshift({"rev": doc_tree.rev, "status": doc_tree.status}); tmp_revs_info.unshift({
"rev": doc_tree.rev,
"status": doc_tree.status
});
} }
if (doc_tree.children.length === 0) { if (doc_tree.children.length === 0) {
if (revs_info.length === 0 || if (revs_info.length === 0 ||
...@@ -532,7 +548,8 @@ jIO.addStorageType("revision", function (spec, my) { ...@@ -532,7 +548,8 @@ jIO.addStorageType("revision", function (spec, my) {
priv.getRevisionTree(doc, option, callback.getRevisionTree); priv.getRevisionTree(doc, option, callback.getRevisionTree);
}; };
callback.getRevisionTree = function (err, response) { callback.getRevisionTree = function (err, response) {
var winner_info, previous_revision = doc._rev, var winner_info, previous_revision, generate_new_revision;
previous_revision = doc._rew;
generate_new_revision = doc._revs || doc._revs_info ? false : true; generate_new_revision = doc._revs || doc._revs_info ? false : true;
if (err) { if (err) {
if (err.status !== 404) { if (err.status !== 404) {
...@@ -949,7 +966,8 @@ jIO.addStorageType("revision", function (spec, my) { ...@@ -949,7 +966,8 @@ jIO.addStorageType("revision", function (spec, my) {
that.success(result); that.success(result);
} }
}; };
priv.send("allDocs", null, command.cloneOption(), function (err, response) { priv.send("allDocs", null, command.cloneOption(
), function (err, response) {
var i, j, row, selector, selected; var i, j, row, selector, selected;
if (err) { if (err) {
return that.error(err); return that.error(err);
...@@ -1019,4 +1037,6 @@ jIO.addStorageType("revision", function (spec, my) { ...@@ -1019,4 +1037,6 @@ jIO.addStorageType("revision", function (spec, my) {
// END // // END //
priv.RevisionStorage(); priv.RevisionStorage();
return that; return that;
}); // end RevisionStorage }); // end RevisionStorage
}));
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