• Get the conflicts associated with a property

    The values of properties in a map in automerge can be conflicted if there are concurrent "put" operations to the same key. Automerge chooses one value arbitrarily (but deterministically, any two nodes who have the same set of changes will choose the same value) from the set of conflicting values to present as the value of the key.

    Sometimes you may want to examine these conflicts, in this case you can use getConflicts to get the conflicts for the key.


    import * as automerge from "@automerge/automerge"

    type Profile = {
    pets: Array<{name: string, type: string}>

    let doc1 = automerge.init<Profile>("aaaa")
    doc1 = automerge.change(doc1, d => {
    d.pets = [{name: "Lassie", type: "dog"}]
    let doc2 = automerge.init<Profile>("bbbb")
    doc2 = automerge.merge(doc2, automerge.clone(doc1))

    doc2 = automerge.change(doc2, d => {
    d.pets[0].name = "Beethoven"

    doc1 = automerge.change(doc1, d => {
    d.pets[0].name = "Babe"

    const doc3 = automerge.merge(doc1, doc2)

    // Note that here we pass `doc3.pets`, not `doc3`
    let conflicts = automerge.getConflicts(doc3.pets[0], "name")

    // The two conflicting values are the keys of the conflicts object
    assert.deepEqual(Object.values(conflicts), ["Babe", "Beethoven"])

    Type Parameters

    • T


    Returns Conflicts | undefined

Generated using TypeDoc