Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Maps #60

Closed
Tjorriemorrie opened this issue Dec 8, 2015 · 4 comments
Closed

Support for Maps #60

Tjorriemorrie opened this issue Dec 8, 2015 · 4 comments

Comments

@Tjorriemorrie
Copy link

Can support be added for ES2015 Map data structures? Converting it to and from json does not correctly convert Maps.

@arqex
Copy link
Owner

arqex commented Dec 15, 2015

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.

@Tjorriemorrie
Copy link
Author

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?

@arqex
Copy link
Owner

arqex commented Dec 16, 2015

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.

@Tjorriemorrie
Copy link
Author

Thank you for the detailed explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants