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

Serializing es6 classes by calling toJSON #37

Open
Parez opened this issue Jun 5, 2017 · 1 comment
Open

Serializing es6 classes by calling toJSON #37

Parez opened this issue Jun 5, 2017 · 1 comment

Comments

@Parez
Copy link

Parez commented Jun 5, 2017

I wish I could put my redux state as is to the toJSON method without worrying that all data structures inside have to belong to immutable.js. Maybe I'm missing something, but at the moment I'm getting an error when I try to serialize Map<string, Item>, where Item is a basic class with a constructor.
The thing is that JSON.stringify does the job of serializing es6 classes just fine by only including it's properties and ignoring methods. I would expect that the library would handle non-immutable objects the same way as JSON.stringify does - then it would be a nice neat extension for normal serialization.

@glenjamin
Copy link
Owner

If you JSON stringify an ES6 Map and then try and parse it back, what do you end up with?

The transit library that powers this one expect every class to be registered so it can encode and decode without loss of detail.

You can use https://github.com/glenjamin/transit-immutable-js#transitwithextrahandlersarray-handlers--transit to include additional handlers, supporting ES6 Maps out of the box would require a change to transit-js itself.

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