Upstatement / jquery-total-storage

A jQuery plugin to manage local storage and cookies simultaneously in a simple interface
http://upstatement.com/blog/2012/01/jquery-local-storage-done-right-and-easy/
151 stars 66 forks source link

parseResult and String parameters #5

Closed schlingel closed 11 years ago

schlingel commented 11 years ago

I got strange results when I tried to add String values to the localStorage. E.g.

jQuery.totalStorage('Klaus', 'asdf'); console.log(jQuery.totalStorage('Klaus'));

printed undefined.

That's because in my Chrome browser JSON.parse throws an SyntaxError exception, so I had to add return res in the catch branch.

Now it works.

Leonya commented 11 years ago

Hm, I don't see how that could happen, but there's a different problem. If you use totalStorage both to set and retrieve a value everything should work fine because it performs JSON.stringify on value set and JSON.parse on value get.

However, if you set the value natively using window.localStorage.setItem('key', 'value'), you will not be able to retrieve it using totalStorage, as it would fail in parseResult as you've noted.

Basically, totalStorage is trying to accomodate all input values and sacrifices transparency while doing so.

jarednova commented 11 years ago

Thanks for the heads-up on this. I've fixed the code to work with window.localStorage.setItem so that values can go back-and-forth.