Skip to content

Commit

Permalink
#23 Moved logic for is localstorage function into anonymous function …
Browse files Browse the repository at this point in the history
…which gets immediately called and set in a var for reuse
  • Loading branch information
Dave committed Mar 11, 2021
1 parent 67b4c8c commit 1b6f52a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var inMemoryStore = {
}
};

function isSupportedNatively() {
var isSupportedNatively = (function() {
try {
if (!window.localStorage) return false;
var key = uuid();
Expand All @@ -47,17 +47,17 @@ function isSupportedNatively() {
// Can throw if localStorage is disabled
return false;
}
}
}());

function pickStorage() {
if (isSupportedNatively()) {
if (isSupportedNatively) {
return window.localStorage;
}
// fall back to in-memory
return inMemoryStore;
}

function isReadSupportedNatively() {
var isReadSupportedNatively = (function() {
try {
if (!window.localStorage) return false;
var key = window.localStorage.key(0);
Expand All @@ -69,10 +69,10 @@ function isReadSupportedNatively() {
// Can throw if localStorage is disabled
return false;
}
}
}());

function pickReclaimStorage() {
if (isReadSupportedNatively()) {
if (isSupportedNatively || isReadSupportedNatively) {
return window.localStorage;
}
// fall back to in-memory
Expand Down

0 comments on commit 1b6f52a

Please sign in to comment.