mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 19:42:50 -06:00
localstorage.js: bug fix
If you stored "false" and tried to retrieve it with a default value, you got the default value instead of "false".
This commit is contained in:
@@ -15,15 +15,15 @@ var fakedLocalStorage = [] // a shared substitute for persistent localStorage
|
|||||||
// An interface to localStorage, to store JSON data under a unique prefix
|
// An interface to localStorage, to store JSON data under a unique prefix
|
||||||
function appLocalStorage(appPrefix,privateStorage) {
|
function appLocalStorage(appPrefix,privateStorage) {
|
||||||
|
|
||||||
function parse(s) {
|
function parse(s,def) {
|
||||||
try { return JSON.parse(s) } catch(e) { return null }
|
try { return JSON.parse(s) } catch(e) { return def }
|
||||||
}
|
}
|
||||||
|
|
||||||
function methods(storage) {
|
function methods(storage) {
|
||||||
return {
|
return {
|
||||||
get: function (name,def) {
|
get: function (name,def) {
|
||||||
var id=appPrefix+name
|
var id=appPrefix+name
|
||||||
return storage[id] && parse(storage[id]) || def;
|
return parse(storage[id]||"",def);
|
||||||
},
|
},
|
||||||
put: function (name,value) {
|
put: function (name,value) {
|
||||||
var id=appPrefix+name;
|
var id=appPrefix+name;
|
||||||
@@ -34,7 +34,7 @@ function appLocalStorage(appPrefix,privateStorage) {
|
|||||||
delete storage[id]
|
delete storage[id]
|
||||||
},
|
},
|
||||||
ls: function(prefix) {
|
ls: function(prefix) {
|
||||||
var pre=appPrefix+prefix
|
var pre=appPrefix+(prefix||"")
|
||||||
var files=[]
|
var files=[]
|
||||||
for(var i in storage)
|
for(var i in storage)
|
||||||
if(hasPrefix(i,pre)) files.push(i.substr(pre.length))
|
if(hasPrefix(i,pre)) files.push(i.substr(pre.length))
|
||||||
|
|||||||
Reference in New Issue
Block a user