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

Could we add a method or option to coerce normal json objects and arrays into immutable Maps and Lists during deserialization #22

Open
jeffbski opened this issue Jun 24, 2016 · 3 comments

Comments

@jeffbski
Copy link

Thanks for creating this project, using transit with immutable.js is awesome. You've packaged up some great functionality here, especially with handling records too.

I was wondering if we could add another method or option that would coerce normal json objects and arrays into immutable maps and lists during deserialization.

Here is the use case I am looking at.

With the methods you have now, it is easy to serialize immutable maps, lists, records into transit format and then deserialize them back into the same form. However on the server if we are fetching from a service or database we might not have immutable maps and lists, so rather than convert the standard objects and arrays it would be nice to simply serialize this (as is) and then coerce them on the client into the immutable maps and lists. On the server we are probably getting back json or objects so it would be more efficient to just send them along as is without a conversion first.

Then we just create maps and lists when we read the transit objects and arrays.

I believe that in doing this we could also support just pure json directly since transit is built on it. So thus whether the server is sending transit encoded objects and arrays or it is just pure json, the reader could create immutable maps and lists from either stream.

This lets us keep things in immutable structures on the client that are created directly upon deserializing the transit stream and on the server we can stay efficient serving transit or json from objects and arrays.

Hopefully this all makes sense. I believe I have some somewhere that setup this type of mapping if I need to dig it up, but I'm expecting that you already know how to make this happen given your effort on the project.

Let me know what you think.

@glenjamin
Copy link
Owner

Seems like a sensible idea to me, its not something I'm likely to work on myself but I'll happily review and help land a PR

@jeffbski
Copy link
Author

Sounds good. I'll start up a PR in the near future and we can take it from there.

@nkbt
Copy link

nkbt commented Jun 25, 2016

That's pretty cool, thanks!

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

3 participants