Strictly this isn't necessary, but eventually I want to move to something more
async for the storage, and this simulates that much better.
setTimeout(util.resolver(def, function () {
key = self.prefix + key;
var value = self.storage.getItem(key);
if (! value) {
value = defaultValue;
if (DEBUG_STORAGE) {
console.debug("Get storage", key, "defaults to", value);
}
} else {
value = JSON.parse(value);
if (DEBUG_STORAGE) {
console.debug("Get storage", key, "=", value);
}
}
return value;
}));
});
},
set: function (key, value) {
var self = this;
if (value !== undefined) {
value = JSON.stringify(value);
}
return Deferred(function (def) {
setTimeout(util.resolver(def, function () {
key = self.prefix + key;
if (value === undefined) {
self.storage.removeItem(key);
if (DEBUG_STORAGE) {
console.debug("Delete storage", key);
}
} else {
self.storage.setItem(key, value);
if (DEBUG_STORAGE) {
console.debug("Set storage", key, value);
}
}
}));
});
},
clear: function () {
var self = this;
var promises = [];
return Deferred((function (def) {
this.keys().then(function (keys) {
keys.forEach(function (key) {