Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_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))
}
}
}
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)
}
})
}
toFrontend() {
const front = Frontend.init("_")
return this._back ? Frontend.applyPatch(front, Backend.getPatch(this._back)) : front
}
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)
}
})
}
setActorId(actorId) {
if (!this._front) {
this._front = Frontend.init(actorId)
this.emit("ready")
}
}