-
Notifications
You must be signed in to change notification settings - Fork 576
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
Add toJSON implementation and testing #4966
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some things I am not sure about
// Check that the serializable object is the same as the first related object. | ||
// (this check only makes sense because of our structure) | ||
expect(serializable).equals(serializable.related[0]); | ||
const relatedObjects = serializable.related as Array<typeof serializable>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if using typeof serializable
is okay here / in general, not too familiar with practices just yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some things that seems worthy to note
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a few comments. This is very close to mergeable.
What, How & Why?
This is a breaking change in sense that it reintroduces
toJSON
functionality with the binding generator but removesJSONSerializerReplacer
. Instead, users are advised to use external libraries such as flatted and @ungap/structured-clone if they need to deal with serialising objects with circular references into a JSON string.The expected functionality of
toJSON
is therefore to generate valid, plain JavaScript objects with correct circular references so those can be used by the packages mentioned above. Current implementation supports Objects and Collections. It is nearly completely ported from pre-bindgen implementation, see this for objects and this for collections. Some changes were made to adapt both to the current state of the API and possibly improve performance by using a 2D map.This PR is not complete and still needs feedback regarding some approaches and testing, see my review for details.
This closes #4949
☑️ ToDos
Compatibility
label is updated or copied from previous entryCOMPATIBILITY.md
package.json
s (if updating internal packages)Breaking
label has been applied or is not necessaryIf this PR adds or changes public API's: