-
Notifications
You must be signed in to change notification settings - Fork 62
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
Provide reviver instead of parseImmutable #188
Comments
@nicolo-ribaudo yeah fair enough. I would definitely be interested in champion's opinions on this then. |
so is the only purpose then of |
Part of this is ergonomics. This feature is very frequently requested. Another part is optimizability: engines can avoid generating the intermediate objects if this is a built-in function, and it may be harder if it's just a parameter to |
On the point of ergonomics, another major downside with only providing a reviver is that revivers do not compose easily, meaning that it would be difficult to simultaneously parse to immutable data structures and do any sort of custom reviving logic. |
I don't think there's any perf component to it, the engine can tell the reviver is Record.jsonReviver the same way it can tell the callee is JSON.parse. I think the main question is how hard/easy it is to compose revivers. if it's difficult we probably shouldn't do this. if it's easy this pattern might be worth exploring. My understanding of the reviver API is that it should be pretty easy to compose them: JSON.parse(s, (k, v) => reviver1(k, reviver2(k, v)) |
The complexity with composing revivers is mostly around the rest of the API surface: that returning |
Yeah the receiver is awkward I guess. I think this could still be an interesting path to take given interest in finding answers to the various problems. Of course if I'm the only one who finds this pattern worthwhile we could choose not to pursue it as well. |
For the reasons listed by @littledan I think we want to keep |
I couldn't find an issue about this, but it would be interesting if, instead of adding a new
JSON.parseImmutable
, we did something likeJSON.parse(source, Record.JSONSourceReviver)
.The text was updated successfully, but these errors were encountered: