Skip to main content
Module

x/automerge/stable.ts>change

A JSON-like data structure (a CRDT) that can be modified concurrently by different users, and merged again automatically.
Go to Latest
function change
import { change } from "https://deno.land/x/automerge@2.2.0/stable.ts";

Update the contents of an automerge document

Examples

A simple change

let doc1 = automerge.init()
doc1 = automerge.change(doc1, d => {
    d.key = "value"
})
assert.equal(doc1.key, "value")

A change with a message

doc1 = automerge.change(doc1, "add another value", d => {
    d.key2 = "value2"
})

A change with a message and a timestamp

doc1 = automerge.change(doc1, {message: "add another value", time: 1640995200}, d => {
    d.key2 = "value2"
})

responding to a patch callback

let patchedPath
let patchCallback = patch => {
   patchedPath = patch.path
}
doc1 = automerge.change(doc1, {message: "add another value", time: 1640995200, patchCallback}, d => {
    d.key2 = "value2"
})
assert.equal(patchedPath, ["key2"])

Parameters

doc: Doc<T>
  • The document to update
options: string | ChangeOptions<T> | ChangeFn<T>
optional
callback: ChangeFn<T>
  • A ChangeFn to be used if options was a string

Note that if the second argument is a function it will be used as the ChangeFn regardless of what the third argument is.