Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.changeQ.subscribe(fn => {
const doc = Frontend.change(this.front, fn)
const request = Frontend.getRequests(doc).pop()
this.front = doc
log(
`change complete doc=${this.docId} seq=${
request ? request.seq : "null"
}`,
)
if (request) {
this.emit("doc", this.front)
this.emit("request", request)
}
})
}
this.pFront.then(() => {
this._front = Frontend.change(this._front, fn)
this.emit("doc",this._front)
this.emit("requests", Frontend.getRequests(this._front))
})
}
change = (cfn: ChangeFn) => {
if (!this.doc) throw new Error("Cannot call change before doc has loaded.")
this.doc = Automerge.change(this.doc, cfn)
const requests = Automerge.getRequests(this.doc)
this.port.postMessage(requests)
this.listeners.forEach(fn => fn(this.doc))
}