From 5f0328ff42c1072708a3ecf3076f6f7b13140f84 Mon Sep 17 00:00:00 2001 From: Dave Date: Thu, 12 Nov 2020 09:37:21 +1100 Subject: [PATCH] #23 Moved logic for is localstorage function into anonymous function which gets immediately called and set in a var for reuse --- lib/engine.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/engine.js b/lib/engine.js index bb61f65..4f53eaf 100644 --- a/lib/engine.js +++ b/lib/engine.js @@ -33,7 +33,7 @@ var inMemoryStore = { } }; -function isSupportedNatively() { +var isSupportedNatively = (function() { try { if (!window.localStorage) return false; var key = uuid(); @@ -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); @@ -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