Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
create(keys) {
const docId = Misc_1.encodeDocId(keys.publicKey);
log('create', docId);
const doc = new DocBackend.DocBackend(docId, automerge_1.Backend.init());
doc.updateQ.subscribe(this.documentNotify);
// HACK: We set a clock value of zero so we have a clock in the clock store
// TODO: This isn't right.
this.clocks.set(this.id, doc.id, { [doc.id]: 0 });
this.docs.set(docId, doc);
this.cursors.addActor(this.id, doc.id, Misc_1.rootActorId(doc.id));
this.initActor(keys);
return doc;
}
// TODO: Temporary solution to replace meta.localActorId
}
this.toFrontend.push({
type: 'Reply',
id,
payload: { type: 'MetadataReplyMsg', metadata: payload },
});
});
break;
}
case 'MaterializeMsg': {
const doc = this.docs.get(query.id);
const changes = doc.back
.getIn(['opSet', 'history'])
.slice(0, query.history)
.toArray();
const [, patch] = automerge_1.Backend.applyChanges(automerge_1.Backend.init(), changes);
this.toFrontend.push({ type: 'Reply', id, payload: { type: 'MaterializeReplyMsg', patch } });
break;
}
}
});
this.receive = (msg) => {
this.bench('applyRemoteChanges', () => {
const [back, patch] = automerge_1.Backend.applyChanges(this.back, changes);
this.back = back;
this.updateClock(changes);
const history = this.back.getIn(['opSet', 'history']).size;
this.updateQ.push({
type: 'RemotePatchMsg',
doc: this,
patch,
history,
});
});
});