mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
refactor(storage) add exec, json, type
This commit is contained in:
parent
d31345203f
commit
b5ba15a9aa
1 changed files with 13 additions and 12 deletions
|
|
@ -1,6 +1,7 @@
|
|||
var Util, DOM;
|
||||
/* global Util */
|
||||
/* global DOM */
|
||||
|
||||
(function(Util, DOM) {
|
||||
(function(Util, DOM, localStorage, exec, json, type) {
|
||||
'use strict';
|
||||
|
||||
var Storage = Util.extendProto(StorageProto),
|
||||
|
|
@ -16,7 +17,7 @@ var Util, DOM;
|
|||
|
||||
/* функция проверяет возможно ли работать с кэшем каким-либо образом */
|
||||
this.isAllowed = function() {
|
||||
var ret = Allowed && !!window.localStorage;
|
||||
var ret = Allowed && !!localStorage;
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
|
@ -34,7 +35,7 @@ var Util, DOM;
|
|||
if (ret)
|
||||
localStorage.removeItem(item);
|
||||
|
||||
Util.exec(callback, null, ret);
|
||||
exec(callback, null, ret);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
|
@ -49,7 +50,7 @@ var Util, DOM;
|
|||
localStorage.removeItem(name);
|
||||
});
|
||||
|
||||
Util.exec(callback);
|
||||
exec(callback);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
|
@ -61,15 +62,15 @@ var Util, DOM;
|
|||
this.set = function(name, data, callback) {
|
||||
var str, error;
|
||||
|
||||
if (Util.type.object(data))
|
||||
str = Util.json.stringify(data);
|
||||
if (type.object(data))
|
||||
str = json.stringify(data);
|
||||
|
||||
if (Allowed && name)
|
||||
error = Util.exec.try(function() {
|
||||
error = exec.try(function() {
|
||||
localStorage.setItem(name, str || data);
|
||||
});
|
||||
|
||||
Util.exec(callback, error);
|
||||
exec(callback, error);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
|
@ -81,7 +82,7 @@ var Util, DOM;
|
|||
if (Allowed)
|
||||
ret = localStorage.getItem(name);
|
||||
|
||||
Util.exec(callback, null, ret);
|
||||
exec(callback, null, ret);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
|
@ -93,9 +94,9 @@ var Util, DOM;
|
|||
if (ret)
|
||||
localStorage.clear();
|
||||
|
||||
Util.exec(callback, null, ret);
|
||||
exec(callback, null, ret);
|
||||
|
||||
return this;
|
||||
};
|
||||
}
|
||||
})(Util, DOM);
|
||||
})(Util, DOM, localStorage, Util.exec, Util.json, Util.type);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue