-
Notifications
You must be signed in to change notification settings - Fork 31
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
undefined
Map key is serialized to null
#33
Comments
Not like I am trying to abuse this library (though probably it looks like I very much do...), but just spent another hour debugging one edge case, where we rely on key being |
There is no |
It is possible. Something like: function __UNDEFINED () {}
const value = typeof input === 'undefined' ? new __UNDEFINED() : value But I feel like it may be done on |
I'm not following that last post - the json spec doesn't include undefined, so short of another fancy encoding I'm not really sure what your options are. Can you change the code so you don't rely on undefined and null needing to be distinct keys? |
Sure, I've changed the code first thing, so this is definitely not a blocker. |
Ah, I see what you mean - yeah. I think transit mostly expects to deal with classes and instances, but the default fallback handler might be a way to encode undefined. |
@nkbt This might help you: https://github.com/deanlandolt/bytewise |
@lukaswelinder that's really cool, thank you! |
@nkbt Glad I could help! Ran into this issue at work. We built out an Immutable.js data store w/ type and order persistence on top of LevelUP and Thread.js and needed a way to serialize Immutable structures for both the DB and to pass messages on Thread.js. In short, our solution was to break down structures into keyPath (arrays) serialized using bytewise w/ our own semantic for identifying structure type. The result takes up more memory than transit-immutable-js however, so you would probably want to only use it for |
So far the easy solution was to switch to null instead. It did not make too much difference for the code around it. But I see bytewise lib as potentially very helpful in some near future for our projects. |
Codepen: http://codepen.io/nkbt/pen/xgebxL
This code
Resulted in
The text was updated successfully, but these errors were encountered: