Closed raphael10-collab closed 2 years ago
Hi @raphael10-collab, one way is to register a patchCallback function which gets called every time a document is updated:
let doc = Automerge.init({patchCallback(patch) {
console.log(patch)
}})
doc = Automerge.change(doc, doc => doc.x = 'y')
The format of the patch is somewhat different to the Automerge 0.x diff format, but it contains essentially the same information. The type definitions document the structure of a patch.
Does that help?
So.... as far as I understand, at the moment, to get Automerge.diff
I can use something like this in type.d.ts
:
let doc = Automerge.init({patchCallback(patch) {
return [doc, patch.diff]
}})
----> doc[1] is the "old" Automerge.diff
?
Returning a value from the patchCallback will have no effect since its return value is ignored. As I said, the diff
field in the patch has a somewhat different structure from the old diff format, but it should hopefully be self-explanatory if you try it with a few examples, or look at the tests, which contain lots of examples of patches.
With the old Automerge.diff, you would pass in two document versions and get back the differences between them. The patchCallback is a bit different, because it gets called as soon as a change is applied. If you want to specifically compare two given document versions, you can do that by cloning the older version, applying the changes between the older and the newer version to the older version, and record the patch resulting from applying those changes.
Thank you Martin. I close the issue for now
Hi! I need to know how to port in old app the Automerge.diff if it is remove from automerge v1.0
Example:
How to substitute Automerge.diff ?