Open popojargo opened 5 years ago
@mattphillips Can you take a look a this?
Hi, user here. Drivebying with a lightning review.
Things that made me think:
Could you describe in English what exactly is wrong that you're attempting to fix?
What exactly does this failure you mention look like? You've posted code to replicate it, but I don't know what I'm looking at, or what the output is, or what you expected the output to be.
Your changes only modify existing tests. Perhaps there should be a test for this case specifically?
Hopefully this is helpful :running_man:
@anko
Basically, I'm using CouchDB has a database. When updating a document, I need to do a partial update
in order to update only the fields that have changed. When manipulating objects with diff
, it works fine. Although, the array handling by default is not very good.
For this reason, I use preserve-array.js which keeps the array and produce a real "array difference".
So let's say I had originally this document:
{
"children": [{"name":1}]
}
and I end up with this document:
{
"children": [{"name":1},{"name":2}]
}
I would like the following diff to apply to the latest document:
{
"children": [empty,{"name":2}]
}
Using the "preserve-array" works fine with array of primitives (number, string). When I'm using arrays of objects, the code just crash since the lhs or rhs can be null at some point.
Yes I did change the tests but the changes I made are testing the object diff. Since a lot of "test cases" were covered in a single test case, I simply added the new things to cover. I can make it more explicit if required.
Speaking of which -- why is preserve-array in the repo when it appears unused? And it's also undocumented.
Your examples with works fine execpt when the values compared in the array are objects.
For example. this will work fine:
But, if you use a similar representation with objects, it fails: