How to use the automerge.save 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 / index.ts View on Github external
for (var key in item) {
            change[key] = item[key];
          }
        });
        const changes = Automerge.getChanges(doc, newDoc);
        const latestActor = changes.length
          ? changes[changes.length - 1].actor
          : actor;
        delta.push([id, changes, rev]);
        return {
          ...item,
          [actorField]: latestActor,
          id,
          // rem,
          rev,
          [mergeField]: Automerge.save(newDoc)
        };
      });
github bkniffler / debe / src / delta / merge.ts View on Github external
/* if (!history.length) {
      return {
        ...snapshot,
        actor: undefined,
        id,
        merge: Automerge.save(docNew)
      };
    }*/
      const history = Automerge.getHistory(docNew);
      const { change, snapshot } = history[history.length - 1];
      return {
        ...snapshot,
        actor: change.actor,
        id,
        merge: Automerge.save(docNew)
      };
    })
    .filter(x => x);
github cudr / slate-collaborative / packages / backend / src / Connection.ts View on Github external
private onConnect = socket => {
    const { id, conn } = socket
    const { name } = socket.nsp

    const doc = this.docSet.getDoc(name)

    const data = Automerge.save(doc)

    this.connections[id] = new Automerge.Connection(this.docSet, data => {
      socket.emit('operation', { id: conn.id, ...data })
    })

    socket.join(id, () => {
      this.connections[id].open()

      socket.emit('document', data)
    })

    socket.on('operation', this.onOperation(id, name))

    socket.on('disconnect', this.onDisconnect(id, socket))

    this.garbageCursors(name)
github automerge / mpl / src / mpl / store.js View on Github external
save() {
    return Automerge.save(this.getState())
  }
github bkniffler / debe / src / automerge / index.ts View on Github external
doc[key] = item[key];
            }
          });
        }
        if (cb) {
          cb(doc);
        }
      });
      const history = Automerge.getHistory(doc);
      item = JSON.parse(JSON.stringify(history[history.length - 1].snapshot));
      item.changes = originalChanges + 1;
      item.id = id;
      if (wasDel) {
        item.isRemoved = wasDel;
      }
      item.automerge = Automerge.save(doc);
      item = await client.insert(table, item);
      return item;
    } catch (err) {
      return Promise.reject(err);
    }
  }
  return edit;
github fluid-notion / fluid-outliner / core / models / OutlineShell.ts View on Github external
public async serialize() {
        return AutoMerge.save(this.outline)
    }
github fluid-notion / fluid-outliner / core / models / EmbeddedCRDTFile.ts View on Github external
public serialize() {
        return AutoMerge.save(this.crdt)
    }