Skip to content

Commit

Permalink
fix(persist): don't show warning message on clean storage (#205)
Browse files Browse the repository at this point in the history
fixed test for using wrong key on storage

fix #199
close #205
  • Loading branch information
happyhj committed May 12, 2016
1 parent ab5036c commit d92078d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/plugin/persist.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions test/unit/js/persist.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit d92078d

Please sign in to comment.