How to use the automerge/backend.applyChanges 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 inkandswitch / capstone / src / node_modules / hypermerge / backend.ts View on Github external
this.bench("init", () => {
      const [back, patch] = Backend.applyChanges(Backend.init(), changes)
      this.actorId = actorId
      if (this.wantsActor && !actorId) {
        this.actorId = this.hypermerge.initActorFeed(this)
      }
      this.back = back
      this.backLocalQ.subscribe(f => f())
      this.backRemoteQ.subscribe(f => f())
      this.emit("ready", this.actorId, patch)
    })
  }
github automerge / hypermerge / src / DocBackend.ts View on Github external
this.bench("init", () => {
      const [back, patch] = Backend.applyChanges(Backend.init(), changes);
      this.actorId = actorId;
      if (this.wantsActor && !actorId) {
        this.actorId = this.repo.initActorFeed(this);
      }
      this.back = back;
      this.updateClock(changes);
      this.subscribeToLocalChanges();
      this.subscribeToRemoteChanges();
      const history = (this.back as any).getIn(["opSet", "history"]).size;
      this.repo.toFrontend.push({
        type: "ReadyMsg",
        id: this.id,
        actorId: this.actorId,
        patch,
        history
      });
github inkandswitch / capstone / src / node_modules / hypermerge / backend.ts View on Github external
this.bench("applyRemoteChanges", () => {
        const [back, patch] = Backend.applyChanges(this.back!, changes)
        this.back = back
        this.emit("patch", patch)
      })
    })
github inkandswitch / capstone / src / modules / hypermerge / index.js View on Github external
applyChanges(docId, changes, local) {
    log("applyChanges", docId)

    if (changes.length === 0) return

    const oldDoc = this.find(docId)

    const filteredChanges = this._filterChanges(changes)

    const [newDoc, patches] = Backend.applyChanges(
      oldDoc,
      filteredChanges,
      true,
    )

    this._recordChanges(docId, newDoc, filteredChanges, local)

    this._setAndNotify(docId, newDoc, patches)
  }
github automerge / hypermerge / src / DocBackend.ts View on Github external
this.bench("applyRemoteChanges", () => {
        const [back, patch] = Backend.applyChanges(this.back!, changes);
        this.back = back;
        this.updateClock(changes);
        const history = (this.back as any).getIn(["opSet", "history"]).size;
        this.repo.toFrontend.push({
          type: "PatchMsg",
          id: this.id,
          patch,
          history
        });
      });
    });