-
Notifications
You must be signed in to change notification settings - Fork 36
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
Treat empty objects as null #51
Conversation
Great, thanks! But, I just realized that there's no obviously correct behaviour here. I was thinking of Firebase's It would involve extending the API, but I could work on adding an argument to |
I am not sure I follow about the issue with update. An update ( |
Hmm. I think for
|
@@ -3,6 +3,14 @@ | |||
|
|||
var merge = require('lodash.mergewith'); | |||
|
|||
function isEmptyObj (obj) { | |||
return obj && typeof obj == 'object' && Object.keys(obj).length === 0 && obj.constructor === Object; |
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.
Why do you need to check the constructor?
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.
per here, a new Date()
would also pass as an empty object without the extra check.
Test a patch with an empty object doesn’t set the node to patch to null. Also Fix goldibex#53 since patch with empty object was throwing.
I fixed the formatting issue and added a test to make sure update operations (tryPatch) are not affected. @mhuebert can you please review and it would work for your use cases? If you are looking for alternative, you could leave the underlying data intact (keep setting nodes to empty objects) and update |
Thanks for the formatting fix. I've added tests for some additional behaviour to align with set/update. Four are currently failing, I thought it might be useful to have them reviewed to make sure functionality makes sense. The two main issues - 1 - I wrote some exploratory code earlier this week that resolves some of this and noticed that fixing it breaks some earlier tests, which expect the current merge and null behaviour. |
I merged the changes without tests related to #52. Please Open a new PR with the new tests. |
Looks great. With all of today's merges, all of my tests pass except |
Updates Targaryen to treat empty objects the same as
null
(as Firebase does), with tests.