goatslacker / alt

Isomorphic flux implementation
http://alt.js.org/
3.45k stars 322 forks source link

ES2015 Map on a Store and LocalStorage #663

Open afilp opened 8 years ago

afilp commented 8 years ago

I realized that persistence of an altjs store on localStorage has problems when the store uses an ES2015 (ES6) Map.

The problem is that when the store is retrieved from the localStorage, the Map is retrieved as an Array and not as a Map. This makes the Map functions on this entity to fail.

This is how the store data is set on localStorage: localStorage.setItem(storeName, JSON.stringify(alt.takeSnapshot(storeName)));

...and this is how the store data is retrieved from localStorage: JSON.parse(localStorage.getItem(storeName))

Do you have your own utils to solve this problem of persistence on localStorage and respect the Map entities? If not, is there any solution to this problem without having to not use Map at all?

Thanks.