How to use the automerge.load 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 bkniffler / debe / src / delta / merge.ts View on Github external
.map(([id, changes]) => {
      if (!changes) {
        return;
      }
      let docOld = undefined;
      const isUpdate = map[id + ''] && map[id + ''].merge;
      if (isUpdate) {
        docOld = Automerge.load(map[id + ''].merge);
        updated.push(id);
      } else {
        docOld = Automerge.init();
      }
      const docInt =
        typeof changes === 'string' ? Automerge.load(changes) : undefined;

      const docNew = docInt
        ? Automerge.merge(docOld, docInt)
        : Automerge.applyChanges(docOld, changes);
      if (Object.keys(Automerge.getMissingDeps(docNew)).length) {
        unsuccessful.push(id);
        return;
      }

      /* if (!history.length) {
      return {
        ...snapshot,
        actor: undefined,
        id,
        merge: Automerge.save(docNew)
      };
github bkniffler / debe / src / delta / merge.ts View on Github external
.map(([id, changes]) => {
      if (!changes) {
        return;
      }
      let docOld = undefined;
      const isUpdate = map[id + ''] && map[id + ''].merge;
      if (isUpdate) {
        docOld = Automerge.load(map[id + ''].merge);
        updated.push(id);
      } else {
        docOld = Automerge.init();
      }
      const docInt =
        typeof changes === 'string' ? Automerge.load(changes) : undefined;

      const docNew = docInt
        ? Automerge.merge(docOld, docInt)
        : Automerge.applyChanges(docOld, changes);
      if (Object.keys(Automerge.getMissingDeps(docNew)).length) {
        unsuccessful.push(id);
        return;
      }

      /* if (!history.length) {
github bkniffler / debe / src / automerge / index.ts View on Github external
const cb = typeof idOrCb === 'string' ? cbOrUndefined : idOrCb;
    try {
      let item: any;
      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) {
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
      })
    }
  }
github automerge / mpl / src / mpl / store.js View on Github external
mergeDocument(state, action) {
    return Automerge.merge(state, Automerge.load(action.file))
  }
github fluid-notion / fluid-outliner / core / models / EmbeddedCRDTFile.ts View on Github external
async load() {
        this.crdt = AutoMerge.load(await this.crdtFile.read())
    }
github cudr / slate-collaborative / packages / client / src / Connection.ts View on Github external
recieveDocument = data => {
    const currentDoc = this.docSet.getDoc(this.docId)

    if (!currentDoc) {
      const doc = Automerge.load(data)

      this.docSet.removeDoc(this.docId)

      this.docSet.setDoc(this.docId, doc)

      this.editor.controller.setValue(Value.fromJSON(toJS(doc)))
    }

    this.editor.setFocus()

    this.connection.open()

    this.onConnect && setTimeout(this.onConnect, 0)
  }