-
Notifications
You must be signed in to change notification settings - Fork 3
feat: support objects with prototypes #16
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
base: main
Are you sure you want to change the base?
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.
Pull Request Overview
This PR adds support for objects with custom prototypes by updating the isJsonObject function to use a more permissive type check. Previously, the function only accepted plain objects (with Object constructor), but now it accepts any non-null object type, enabling the library to handle class instances and objects with custom prototypes.
- Modified
isJsonObjectto accept objects with any prototype, not just plain objects - Added comprehensive test coverage for objects with custom prototypes and nested class instances
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/index.ts | Updated isJsonObject to use generic object type check instead of constructor comparison |
| src/index.spec.ts | Added test suite demonstrating JSON patch generation for class instances with nested objects |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b9df809 to
7ce7a9f
Compare
|
Thanks for this @BrianHuf 🙏 So far, this lib doesn't explicitly support any JS classes (Date, Map, Set, RegExp, Array) or custom classes. I want to first support built-ins, before supporting custom classes. depending on what you want to achieve, you could |
|
No problem. Just sharing some changes we're using in a fork. For us, it's all about performance. We were using the Another necessary change for performance (for us) is to do object equality checks. For example, Thanks for the making this library! It's fast, small, and very easy to read. |
|
Hey @BrianHuf, Have you explored to only compare the state product of |
|
Thanks for the thoughtful suggestion! It's true unwrapping the proxy object would solve the problem. |
Add support for objects with prototypes