How to use the automerge/frontend.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 inkandswitch / capstone / src / data / StoreEntry.ts View on Github external
_onMessage = ({ actorId, patch }: any) => {
    if (!this.doc) {
      this.doc = Automerge.init(actorId)
    }

    this.doc = Automerge.applyPatch(this.doc, patch)

    if (Object.keys(this.doc).length > 0) {  // hack - sending the empty docs blows up the app
      this.listeners.forEach(fn => fn(this.doc))
    }
  }
}
github inkandswitch / capstone / src / node_modules / hypermerge / frontend.ts View on Github external
constructor(docId: string, actorId?: string) {
    super()

    if (actorId) {
      this.front = Frontend.init(actorId) as Doc
      this.docId = docId
      this.actorId = actorId
      this.enableWrites()
    } else {
      this.front = Frontend.init({ deferActorId: true }) as Doc
      this.docId = docId
    }

    this.on("newListener", (event, listener) => {
      if (event === "doc" && this.mode != "pending") {
        listener(this.front)
      }
    })
  }
github inkandswitch / capstone / src / modules / hypermerge / backend.js View on Github external
toFrontend() {
    const front = Frontend.init("_")
    return this._back ? Frontend.applyPatch(front, Backend.getPatch(this._back)) : front
  }
github inkandswitch / capstone / src / node_modules / hypermerge / frontend.ts View on Github external
constructor(docId: string, actorId?: string) {
    super()

    if (actorId) {
      this.front = Frontend.init(actorId) as Doc
      this.docId = docId
      this.actorId = actorId
      this.enableWrites()
    } else {
      this.front = Frontend.init({ deferActorId: true }) as Doc
      this.docId = docId
    }

    this.on("newListener", (event, listener) => {
      if (event === "doc" && this.mode != "pending") {
        listener(this.front)
      }
    })
  }
github inkandswitch / capstone / src / modules / hypermerge / frontend.js View on Github external
setActorId(actorId) {
    if (!this._front) {
      this._front = Frontend.init(actorId)
      this.emit("ready")
    }
  }