How to use the automerge.change 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 ahixon / slate-sync-bridge / test / slate / automerge.js View on Github external
fixtures(__dirname, 'operations', ({ module }) => {
      const { input, output } = module
      const operations = module.default

      const inputSyncDoc = toSyncDocument(input.document.toJSON())
      const initAutomergeDoc = Automerge.init();
      const emptyAutomergeDoc = Automerge.change(initAutomergeDoc, automergeDoc => {
        automergeDoc.doc = inputSyncDoc;
      });

      const changedAutomergeDoc = Automerge.change(emptyAutomergeDoc, automergeDoc => {
        operations.forEach(op => applyOperation(automergeDoc.doc, op));
      })

      // check our rep matched
      const expectedDoc = output.document.toJSON();
      const actualDoc = toSlateDocument(changedAutomergeDoc.doc);
      assert.deepEqual(actualDoc, expectedDoc);
    })
github ahixon / slate-sync-bridge / test / slate-diff.jsx View on Github external
)

    const { transformer, loadedDoc } = setup(input);

    // insert text into the second nested paragraph
    const op = {
      type: "insert_text",
      path: [0, 1, 0],
      offset: 5,
      text: 'h',
    }

    // load the cache
    // transformer.apply(loadedDoc.doc);

    const changedDoc = Automerge.change(loadedDoc, doc => applyOperation(doc.doc, op))
    const changes = Automerge.getChanges(loadedDoc, changedDoc);

    const transformed = transformer.apply(changedDoc.doc, changes);
    expect(transformed.toJSON()).toEqual(output.toJSON());
  })
github humandx / slate-automerge / src / libs / slateOpsToAutomerge.js View on Github external
export const applySlateOperations = (docSet, docId, slateOperations, clientId) => {
    const currentDoc = docSet.getDoc(docId)
    if (currentDoc) {
        const message = clientId ? `Client ${clientId}` : "Change log"
        const docNew = Automerge.change(currentDoc, message, doc => {
            // Use the Slate operations to modify the Automerge document.
            applySlateOperationsHelper(doc, slateOperations)
        })
        docSet.setDoc(docId, docNew)
    }
}
github automerge / hypermerge / tests / smoke-test-no-hypercore.js View on Github external
it('2. Alice makes an edit', () => {
    alice2 = Automerge.change(alice1, doc => { doc.x0y0 = 'r' })
    assert.deepEqual(alice2, {
      _objectId: '00000000-0000-0000-0000-000000000000',
      x0y0: 'r',
      x0y1: 'w',
      x1y0: 'w',
      x1y1: 'w'
    })
    bob2 = bob1
  })
github automerge / hypermerge / tests / smoke-test-no-hypercore.js View on Github external
it('5. Both Alice and Bob make edits while offline', () => {
    alice5 = Automerge.change(alice4, doc => {
      doc.x1y0 = 'g'
      doc.x1y1 = 'r'
    })
    bob5 = Automerge.change(bob4, doc => {
      doc.x1y0 = 'g'
      doc.x1y1 = 'w'
    })
    assert.deepEqual(alice5, {
      _objectId: '00000000-0000-0000-0000-000000000000',
      x0y0: 'r',
      x0y1: 'w',
      x1y0: 'g',
      x1y1: 'r'
    })
    assert.deepEqual(bob5, {
      _objectId: '00000000-0000-0000-0000-000000000000',
github cudr / slate-collaborative / packages / bridge / src / utils / testUtils.ts View on Github external
export const cloneDoc = doc => Automerge.change(doc, '', d => d)
github Graphite-Docs / graphite / src / components / graphite / Yjs.js View on Github external
.then((fileContents) => {
              if(fileContents){
                console.log('file loaded number ' + count);
                let object = Automerge.init();
                object = Automerge.change(object, file => {
                  file.team = JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).team;
                  file.integrations = JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).integrations;
                  file.lastUpdated = JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).lastUpdated;
                  file.accountSettings = JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).accountSettings;
                  file.editorView = JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).editorView;
                  file.editorName = JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).editorName;
                  file.editorPermissions = JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).editorPermissions;
                  file.editorIntegrations = JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).editorIntegrations;
                  file.editorPublish = JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).editorPublish;
                  file.journoView = JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).journoView;
                  file.journoName = JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).journoName;
                  file.journoRoles = JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).journoRoles;
                  file.journoPermissions = JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).journoPermissions;
                  file.journoIntegrations = JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).journoIntegrations;
                });
                this.setState({file2: object});
github aslakhellesoy / automerge-codemirror / example / src / app.js View on Github external
updateDoc,
  })
  codeMirror.on('change', codeMirrorHandler)
  docSet.registerHandler((updatedDocId, updatedDoc) => {
    if (updatedDocId === docId) {
      automergeHandler(updatedDoc)
    }
  })
}

createCodeMirror(rightDocSet, 'right')
createCodeMirror(leftDocSet, 'left')

rightDocSet.setDoc(
  docId,
  Automerge.change(Automerge.init(), doc => (doc.text = new Automerge.Text()))
)
github aslakhellesoy / automerge-codemirror / stories / components / PadComponent.tsx View on Github external
function createSheet() {
    watchableDoc.set(
      change(doc, draft => {
        if (draft.sheets == undefined) draft.sheets = []
        draft.sheets.push(new Text())
      })
    )
  }
github frontarm / demoboard / packages / demoboard-core / src / project / demoboardProjectReducer.ts View on Github external
function updateData(
  state: DemoboardProjectState,
  callback: (value: Proxy) => void,
): DemoboardProjectState {
  let commitMessage = Date.now()
  return {
    ...state,
    data: change(state.data, String(commitMessage), callback),
  }
}