-
-
Notifications
You must be signed in to change notification settings - Fork 89
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
is there any apply method ? #71
Comments
That will be really great to have! |
Hi @maxired this library doesn't currently support anything like this. Are you able to give a concrete example of what you would like to happen? I've never used jsonpatch but I would imagine to compute an original object from a diff you would need some sort of metadata to describe the changes (which isn't something currently supported by deep-object-diff). |
Maybe I can give you an use case. I have a functionality where the users must fulfill a multistep form, stored like JSON object in database, and must support versioning, because users can fulfill that as many times as they want. Will be great if I could store just the diffs, and apply them to the schema. Right now I'm busy and couldn't provide an example with code, I would do it later |
Hi @mattphillips, thanks for your answer. But we have this other user use case where we are reevaluating our options. The goal of the server is to merge the different changes and propagate them to other clients. Anyway, at each interval, the server computes a new state and needs to propagate it to the other clients.
TBH, I don't know much about JSON Patch either, but I am not sure it really creates more data than detailedDiff is doing. here is the output corresponding to the diff of detailedDiff [
{
"op": "replace",
"path": "/buzz",
"value": "fizz"
},
{
"op": "remove",
"path": "/foo/bar/e"
},
{
"op": "add",
"path": "/foo/bar/c/2",
"value": "z"
},
{
"op": "remove",
"path": "/foo/bar/a/1"
},
{
"op": "add",
"path": "/foo/bar/d",
"value": "Hello, world!"
}
] we can see it uses an array. Not sure if that's important to keep the order of operation. PS: we are not dealing with conflict between our clients, and so don't need CRDT or similar solutions |
I ended up publishing this as its own npm package: https://www.npmjs.com/package/@transformation-dev/deep-object-diff-apply |
@lmaccherone Looks like your master branch on GH hasn't yet merged in the deep-object-diff-apply package? |
Use case is pretty straight-forward: Using a document-store database (think MongoDB or Firestore). A "document" is simply a JS object (or JSON object). When an update is being done to the document, I want to calculate the diff and store the diff in some type of history or audit collection (table). I can then use those deltas over time to identify who changed what in that object. The document in the main collection is the "current state" of the data, and the diffs in the audit table are the changes to the data over time (in reverse order). A storage-level "version control" for business objects!! :) |
Hi,
I was not able to find any apply method which would allow us to take a diff, and apply it to an object.
Is there one somewhere? Maybe in another repo?
As a user, I want to be able to compute a diff, send it to a remote host, and apply it (reverse it?), to compute the whole object.
Or should I rather use libraries based on jsonpatch ?
The text was updated successfully, but these errors were encountered: