• Update the contents of an automerge document

    Example

    A simple change

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

    Example

    A change with a message

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

    Example

    A change with a message and a timestamp

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

    Example

    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"])

    Type Parameters

    • T

      The type of the value contained in the document

    Parameters

    • doc: Doc<T>

      The document to update

    • options: string | next.ChangeOptions<T> | next.ChangeFn<T>

      Either a message, an ChangeOptions, or a ChangeFn

    • Optional callback: next.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.

    Returns Doc<T>

Generated using TypeDoc