The type of the value contained in the document
The document to update
The heads representing the point in history to make the change
Either a message or a ChangeOptions for the new change
Optional
callback: Automerge.ChangeFn<T>A ChangeFn
to be used if options
was a string
This function is similar to change but allows you to make changes to the document as if it were at a particular point in time. To understand this imagine a document created with the following history:
let doc = automerge.from({..})
doc = automerge.change(doc, () => {...})
const heads = automerge.getHeads(doc)
// fork the document make a change
let fork = automerge.fork(doc)
fork = automerge.change(fork, () => {...})
const headsOnFork = automerge.getHeads(fork)
// make a change on the original doc
doc = automerge.change(doc, () => {...})
const headsOnOriginal = automerge.getHeads(doc)
// now merge the changes back to the original document
doc = automerge.merge(doc, fork)
// The heads of the document will now be (headsOnFork, headsOnOriginal)
ChangeAt produces an equivalent history, but without having to
create a fork of the document. In particular the newHeads
field of the
returned ChangeAtResult will be the same as headsOnFork
.
Why would you want this? It's typically used in conjunction with diff to reconcile state which is managed concurrently with the document. For example, if you have a text editor component which the user is modifying and you can't send the changes to the document synchronously you might follow a workflow like this:
Now from time to time reconcile the editor state and the document
oldHeads
changeAt(doc, oldHeads, ...)
before
argument and the
heads of the entire document as the after
argument.
Make a change to the document as it was at a particular point in history