Skip to content

Instantly share code, notes, and snippets.

@mmcgrana
Created May 15, 2018 20:19
Show Gist options
  • Save mmcgrana/5f4d8391d959a14686ddda655e5c699e to your computer and use it in GitHub Desktop.
Save mmcgrana/5f4d8391d959a14686ddda655e5c699e to your computer and use it in GitHub Desktop.
Automerge = require('automerge')
const docRoot = Automerge.init()
const doc1 = Automerge.change(docRoot, (doc) => {
doc.foo = []
})
const change1 = Automerge.getChanges(docRoot, doc1)
const doc2 = Automerge.change(doc1, (doc) => {
doc.foo.push('a')
})
const change2 = Automerge.getChanges(doc1, doc2)
console.log(change1, change1[0].ops)
console.log(change2, change2[0].ops)
console.log()
const docA = Automerge.applyChanges(docRoot, change2)
console.log(docA)
console.log(Automerge.getMissingDeps(docA))
// Line below throws e.g. `Modification of unknown object 860bacb9-eae2-4035-a257-4a2604c229f4`.
console.log(Automerge.change(docA, (doc) => { doc.biz = 'c' }))
console.log()
const docB = Automerge.applyChanges(docA, change1)
console.log(docB)
console.log(Automerge.getMissingDeps(docB))
console.log(Automerge.change(docB, (doc) => {doc.biz = 'd' }))
// Everything else above works as expected (if the offending line is commented out).
// The error only appears for certain types of blocks given to create doc1 and
// doc2. E.g. if doc1 is created with `(doc) => { doc.foo = 'bar' }` and doc2
// with `(doc) => {doc.foo = 'bat' }`, the error doesn't occur.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment