Commit 5aebc8b2 authored by Tristan Cavelier's avatar Tristan Cavelier

Adding waitStorage

This storage will wait before executing command on another storage.
So there is a parameter "storage" (like indexedstorage).
Wait storage can have some optional parameters:
key     : default value
-----------------------
delay   : 5000,
save    : true, // will wait 5 seconds before saveDocument
load    : false, // won't wait
remove  : false, // ''
getlist : false. // ''
parent 3937200f
......@@ -16,6 +16,7 @@
<script type="text/javascript" src="lib/sjcl/sjcl.min.js"></script>
<script type="text/javascript" src="lib/jio/jio.storage.js"></script>
<script type="text/javascript" src="src/jio.dummystorages.js"></script>
<script type="text/javascript" src="src/jio.waitstorage.js"></script>
</head>
<body>
......
(function () { var jioWaitStorageLoader = function ( Jio ) {
var newWaitStorage = function ( spec, my ) {
var that = Jio.storage( spec, my, 'handler' ), priv = {};
var validatestate_secondstorage = spec.storage || false;
priv.secondstorage_spec = spec.storage || {type:'base'};
priv.delay = spec.delay || 5000;
priv.save = spec.save || true;
priv.load = spec.load || false;
priv.getlist = spec.getlist || false;
priv.remove = spec.remove || false;
that.validateState = function () {
if (!validatestate_secondstorage) {
return 'Need at least one parameter: "storage" '+
'containing storage specifications.';
}
return '';
};
var super_serialized = that.serialized;
that.serialized = function () {
var o = super_serialized();
o.delay = priv.delay;
o.storage = priv.secondstorage_spec;
o.save = priv.save;
o.load = priv.load;
o.getlist = priv.getlist;
o.remove = priv.remove;
return o;
};
priv.doJob = function (command,timeout_or_not_timeout) {
var delay = 0;
if (timeout_or_not_timeout) {
delay = priv.delay;
}
setTimeout (function () {
that.addJob ( that.newStorage(priv.secondstorage_spec),
command );
that.end();
}, delay);
};
that.saveDocument = function (command) {
priv.doJob (command,priv.save);
}; // end saveDocument
that.loadDocument = function (command) {
priv.doJob (command,priv.load);
}; // end loadDocument
that.getDocumentList = function (command) {
priv.doJob (command,priv.getlist);
}; // end getDocumentList
that.removeDocument = function (command) {
priv.doJob (command,priv.remove);
}; // end removeDocument
return that;
};
Jio.addStorageType('wait', newWaitStorage);
};
if (window.requirejs) {
define ('JIOWaitStorages',['JIO'], jioWaitStorageLoader);
} else {
jioWaitStorageLoader ( jio );
}
}());
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