@automerge/automerge - v3.0.0
    Preparing search index...

    Function change

    • Update the contents of an automerge document

      Type Parameters

      • T

        The type of the value contained in the document

      Parameters

      • doc: Doc<T>

        The document to update

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

        Either a message, an ChangeOptions, or a ChangeFn

      • Optionalcallback: 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>

      let doc1 = automerge.init()
      doc1 = automerge.change(doc1, d => {
      d.key = "value"
      })
      assert.equal(doc1.key, "value")
      doc1 = automerge.change(doc1, "add another value", d => {
      d.key2 = "value2"
      })
      doc1 = automerge.change(doc1, {message: "add another value", time: 1640995200}, d => {
      d.key2 = "value2"
      })
      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"])