How to use the automerge.init 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 automerge / hypermerge / tests / smoke-test-no-hypercore.js View on Github external
'Both are online.', () => {
    alice1 = Automerge.change(Automerge.init('alice'), doc => {
      doc.x0y0 = 'w'
      doc.x0y1 = 'w'
      doc.x1y0 = 'w'
      doc.x1y1 = 'w'
    })
    assert.deepEqual(alice1, {
      _objectId: '00000000-0000-0000-0000-000000000000',
      x0y0: 'w',
      x0y1: 'w',
      x1y0: 'w',
      x1y1: 'w'
    })
    bob1 = Automerge.merge(Automerge.init('bob'), alice1)
    assert.deepEqual(bob1, {
      _objectId: '00000000-0000-0000-0000-000000000000',
      x0y0: 'w',
github Graphite-Docs / graphite / src / components / graphite / Yjs.js View on Github external
combineFile() {
    console.log("Starting the saving process...")
    console.log(this.state.team);
    this.setState({ hideMain: "", updateTeammateModal: "hide", teammateName: "", newUserRole: "" });
    //Take loaded states and combine them into a single file
    let object = Automerge.init();
    object = Automerge.change(object, file => {
      file.team = this.state.team;
      file.integrations = this.state.integrations;
      file.lastUpdated = this.state.lastUpdated;
      if(this.state.updatedAccountName && this.state.updatedAccountName !== "") {
        file.accountSettings = this.state.updatedAccountName;
        this.setState({ accountSettings: this.state.updatedAccountName})
      } else {
        file.accountSettings = this.state.accountSettings;
      }
      file.editorView = this.state.editorView;
      file.editorName = this.state.editorName;
      file.editorPermissions = this.state.editorPermissions || false;
      file.editorIntegrations = this.state.editorIntegrations;
      file.editorPublish = this.state.editorPublish;
      file.journoView = this.state.journoView;
github fluid-notion / fluid-outliner / core / models / EmbeddedCRDTFile.ts View on Github external
async safeLoad() {
        if (this.crdtFile.isPersisted()) {
            await this.load()
        } else {
            this.crdt = AutoMerge.change(AutoMerge.init(), (doc: any) => {
                doc.content = new AutoMerge.Text()
            });
        }
    }
github aslakhellesoy / automerge-codemirror / stories / index.stories.tsx View on Github external
() => {
    const watchableDocs = createConnectedDocs(2, 'someid')
    watchableDocs[0].set(
      change(
        init(),
        (draft: Sheet) =>
          (draft.grid = [
            [{ value: 'A' }, { value: 'BBB' }],
            [{ value: 'CCC' }, { value: 'DDD' }],
          ])
      )
    )

    return (
      <div>
        {watchableDocs.map((watchableDoc, n) =&gt; (
          
        ))}
      </div>
    )
  }
github bkniffler / debe / src / automerge / index.ts View on Github external
if (id) {
        item = await client.get(table, {
          id
        });
        if (!item) {
          return Promise.reject(new Error('Could not find item with id ' + id));
        }
      }
      const originalChanges = parseInt((item ? item.changes : 0) || 0);
      const wasDel = item ? item.isRemoved : undefined;
      let doc;
      if (item && item.automerge) {
        doc = Automerge.load(item.automerge);
      }
      if (!doc) {
        doc = Automerge.init();
      }
      doc = Automerge.change(doc, (doc: any) => {
        if (item && !item.automerge) {
          Object.keys(item).forEach(key => {
            if (key === 'id' || key === 'rev' || key === 'rem') {
              return;
            }
            if (item[key] !== undefined && item[key] !== null) {
              doc[key] = item[key];
            }
          });
        }
        if (cb) {
          cb(doc);
        }
      });
github fluid-notion / fluid-outliner / core / models / OutlineShell.ts View on Github external
public static create(embeddedOutlineFile: EmbeddedCRDTFile, repository: Repository) {
        const outline = AutoMerge.change(AutoMerge.init(), (doc: any) =&gt; {
            doc.id = uuid()
            doc.title = "Untitled"
            const defaultNode = createDefaultNode()
            doc.allNodes = {}
            doc.allNodes[defaultNode.id] = defaultNode
            doc.children = [defaultNode.id]
            return doc
        })
        embeddedOutlineFile.crdt = outline
        embeddedOutlineFile.save()
        debug("Creating outline", outline)
        return new this(embeddedOutlineFile, repository)
    }
github humandx / slate-automerge / src / example / server / index.js View on Github external
const createNewDocument = function(docId) {
  let doc = Automerge.init(`server-1234`);
  const initialSlateValue = Value.fromJSON(initialValue);
  doc = Automerge.change(doc, "Initialize Slate state", doc => {
      doc.note = slateCustomToJson(initialSlateValue.document);
  })
  docSet.setDoc(docId, doc);
}
github inkandswitch / pushpin / src / hypermerge / index.js View on Github external
_empty(actorId) {
    return this.immutableApi
      ? Automerge.initImmutable(actorId)
      : Automerge.init(actorId)
  }
github automerge / mpl / src / mpl / store.js View on Github external
openDocument(state, action) {
    if (action.file) return Automerge.load(action.file)

    if (action.docId) {
      let doc = this.docSet.getDoc(action.docId)
      if (doc) return doc

      return Automerge.change(Automerge.init(), { action: action }, (doc) => {
        doc.docId = action.docId
      })
    }
  }