Open gajus opened 8 years ago
I think this could be considered a dupe of #25 - but this has a nice summary so i'm going to close that one instead.
I think it is possible to allow decoding of an object as mentioned in https://github.com/glenjamin/transit-immutable-js/issues/25#issuecomment-240679696 It's currently not possible to encode into an object due to https://github.com/cognitect/transit-js/issues/23
What about a hacky interim solution that would check if input is an object and cast it to a string using JSON.stringify
?
This would abstract the issue at the transit-immutable-js
API level.
There is no performance trade-off, because if you are not doing it – the user of the API will need to do it anyway.
I don't think it'd be that difficult to create a transit.decoder
instance and accept an object without the additional stringify - this issue isn't currently affecting me so it's not high up my list of things to do, but I'd definitely take a PR (and help with landing it).
If it does cross my path requirement-wise in the near future I'll probably tackle it myself.
Sorry, I don't have time to make contributions to new OS projects. Have my hands full.
Sorry, I don't have time to make contributions to new OS projects. Have my hands full.
No worries, I know the feeling!
Use case scenario:
Server renders:
Client picks up
__PRELOADED_STATE__
, which is a valid JSON, therefore it is converted to an object. To use it, I need to cast it back to string, e.g.Alternatively, I can stringify the object twice on server: once using
transit-immutable-js
and second time usingJSON.stringify
, e.g.Preferably though,
transit-immutable-js
should be able to accept an object.