From d92078dcc27fe67b43f87fde81f6df57d40b2a86 Mon Sep 17 00:00:00 2001 From: Hee Jae Kim Date: Thu, 12 May 2016 12:20:34 +0900 Subject: [PATCH] fix(persist): don't show warning message on clean storage (#205) fixed test for using wrong key on storage fix #199 close #205 --- src/plugin/persist.js | 5 +++++ test/unit/js/persist.test.js | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/plugin/persist.js b/src/plugin/persist.js index 2251edd..5cc97db 100644 --- a/src/plugin/persist.js +++ b/src/plugin/persist.js @@ -89,6 +89,11 @@ eg.module("persist", ["jQuery", eg, window, document], function($, ns, global, d var stateStr = storage ? storage.getItem(location.href + CONST_PERSIST) : history.state; + // the storage is clean + if (stateStr === null) { + return {}; + } + // "null" is not a valid var isValidStateStr = typeof stateStr === "string" && stateStr.length > 0 && stateStr !== "null"; diff --git a/test/unit/js/persist.test.js b/test/unit/js/persist.test.js index 94d08b0..643c771 100644 --- a/test/unit/js/persist.test.js +++ b/test/unit/js/persist.test.js @@ -301,8 +301,8 @@ $.each(['{', '[ 1,2,3 ]', '1', '1.234', '"123"'], function(i, v) { var isNoExceptionThrown = true; if(isSupportStorage) { - sessionStorage.setItem("KEY___persist___", v); - localStorage.setItem("KEY___persist___", v); + sessionStorage.setItem(location.href + "___persist___", v); + localStorage.setItem(location.href + "___persist___", v); } else if(isSupportState) { history.replaceState(v, document.title, location.href); }