-
Notifications
You must be signed in to change notification settings - Fork 58
Conversation
@maier49 can you give this a review please? |
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.
My main concern here is how this fits in with the existing comparison API provided in Stores. Stores uses a patch implementation that serializes to JSON Patch.
I think the checks for plain objects and some other things in here are a little better than how Stores is currently handling it, but I don't know if we should replace the diff functionality without answering the question of how we want to serialize patches for sending to the server. If we do want to use JSON Patch, then it seems odd to switch to a patch/diff implementation that doesn't support that from one that does.
Codecov Report
@@ Coverage Diff @@
## master #233 +/- ##
==========================================
+ Coverage 93.88% 94.28% +0.39%
==========================================
Files 39 40 +1
Lines 2144 2309 +165
Branches 408 463 +55
==========================================
+ Hits 2013 2177 +164
Misses 52 52
- Partials 79 80 +1
Continue to review full report at Codecov.
|
The patch implementation in stores could pretty easily be moved over to core. It only relies on a few utility functions outside of the We could address any issues with the API in the process of moving it over. |
@maier49 ok, let's do that! |
So shall we close this pending @maier49's work to move the implementation over from stores? |
I have refreshed this PR from what I have had to do in Also, my understanding is that @pottedmeat had a chat with @maier49 about the usage in stores for dgrid and they agreed that it might be better to take what is here and iterate on it to make it work for stores. If that is still the case, we should land this and figure out if there are any features that are needed for stores. Also, |
@kitsonk the main thing for stores is just providing an appropriately serialized version of a diff for a |
I will take a look at what is in stores (and sorry again for not looking first) and see what it would take to do that. |
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.
Just a few typos
src/compare.ts
Outdated
} | ||
|
||
/** | ||
* An internal function that take a value from array being patched and the target value from the same |
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.
take takes
src/compare.ts
Outdated
} | ||
|
||
/** | ||
* Compares to plain objects or arrays and return a set of records which describe the differences between the two |
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.
to two
[ci skip]
This PR implements a comparison API as part of core.
Fixes #138
The Comparison API can deal with Arrays and "plain" Objects. Plain objects are objects that have either
Object
as a constructor (or no constructor) and the properties values of the object are either primitives, arrays, or plain objects. For objects, only enumerable own properties are considered.The module
compare
exports two functionsdiff
andpatch
.diff()
returns the difference between the first and the second argument and describes the steps to take to make the first object look like the second object.patch()
takes a target and applies a set of changes which will change the target.