How to use the automerge.getObjectId function in automerge

To help you get started, we’ve selected a few automerge examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aslakhellesoy / automerge-codemirror / index.js View on Github external
doc = newDoc
      // We'll replace the entire editor value on the first automerge update
      const fromPos = codeMirror.posFromIndex(0)
      const toPos = codeMirror.posFromIndex(codeMirror.getValue().length)
      codeMirror.replaceRange(
        getText(newDoc).join(''),
        fromPos,
        toPos,
        'automerge'
      )
      return
    }

    // After the first automerge update we update the doc using a diff

    const textObjectId = Automerge.getObjectId(getText(doc))
    const diff = Automerge.diff(doc, newDoc)
    for (const d of diff) {
      if (d.obj !== textObjectId) continue
      switch (d.action) {
        case 'insert': {
          const fromPos = codeMirror.posFromIndex(d.index)
          codeMirror.replaceRange(d.value, fromPos, null, 'automerge')
          break
        }
        case 'remove': {
          const fromPos = codeMirror.posFromIndex(d.index)
          const toPos = codeMirror.posFromIndex(d.index + 1)
          codeMirror.replaceRange('', fromPos, toPos, 'automerge')
          break
        }
      }
github ahixon / slate-sync-bridge / test / slate-diff.jsx View on Github external
const setup = input => {
  const syncJSON = toSyncDocument(input.toJSON());
  const initDoc = Automerge.init();
  const loadedDoc = Automerge.change(initDoc, doc => {
    doc.doc = syncJSON;
  });

  const transformer = new CachedSlateTransformer(Automerge.getObjectId);
  return {
    transformer,
    loadedDoc
  };
};
github aslakhellesoy / automerge-codemirror / dist / src / updateCodeMirrorDocs.js View on Github external
function findLink(newDoc, links, op) {
  var e_2, _a
  try {
    for (
      var links_1 = __values(links), links_1_1 = links_1.next();
      !links_1_1.done;
      links_1_1 = links_1.next()
    ) {
      var link = links_1_1.value
      var text = link.getText(newDoc)
      var textObjectId = automerge_1.getObjectId(text)
      if (op.obj === textObjectId) {
        return link
      }
    }
  } catch (e_2_1) {
    e_2 = { error: e_2_1 }
  } finally {
    try {
      if (links_1_1 && !links_1_1.done && (_a = links_1.return))
        _a.call(links_1)
    } finally {
      if (e_2) throw e_2.error
    }
  }
  return null
}
github aslakhellesoy / automerge-codemirror / src / updateCodeMirrorDocs.ts View on Github external
function findLink(newDoc: T, links: Set>, op: Diff): Link | null {
  for (const link of links) {
    const text = link.getText(newDoc)
    const textObjectId = getObjectId(text)
    if (op.obj === textObjectId) {
      return link
    }
  }
  return null
}