Closed Tjorriemorrie closed 8 years ago
Hi @Tjorriemorrie
Map support is not planned. When you JSON.stringify a map object you get a simple object, and something similar happens when you add it to a freezer store, all the functions get stripped off.
I thought as much. What about passing a possible second argument when the freezer is created from an json object? And that argument is the schema of field types to parse it to?
Trying to parse class instances inside freezer would have a really big downside: those object could be mutated without triggering events.
For example, the Map class has all the getter and setter methods that modify its internal state. Even when you freeze it you are able to use that methods to update it:
var m = new Map(); // Map {}
Object.freeze( m ); // The map should be freezer
m.set('a', 1);
console.log( m ) // Map {"a" => 1} we have just updated the frozen map :(
This way we lose the point of using freezer.
Thank you for the detailed explanation.
Can support be added for ES2015 Map data structures? Converting it to and from json does not correctly convert Maps.