Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
})
}
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
});
this.bench("applyRemoteChanges", () => {
const [back, patch] = Backend.applyChanges(this.back!, changes)
this.back = back
this.emit("patch", patch)
})
})
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)
}
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
});
});
});