Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
const {
rev,
id,
// rem,
[mergeField]: automerge,
[actorField]: actor,
...item
} = i;
const doc = automerge ? Automerge.load(automerge) : Automerge.init();
const newDoc = Automerge.change(doc, message, (change: any) => {
for (var key in item) {
change[key] = item[key];
}
});
const changes = Automerge.getChanges(doc, newDoc);
const latestActor = changes.length
? changes[changes.length - 1].actor
: actor;
delta.push([id, changes, rev]);
return {
...item,
[actorField]: latestActor,
id,
// rem,
rev,
[mergeField]: Automerge.save(newDoc)
};
});
it(`3a. Bob's edit gets synced to Alice's canvas`, () => {
const bobChanges3a = Automerge.getChanges(bob2, bob3)
alice3a = Automerge.applyChanges(alice3, bobChanges3a)
bob3a = bob3
assert.deepEqual(alice3a, {
_objectId: '00000000-0000-0000-0000-000000000000',
x0y0: 'r',
x0y1: 'w',
x1y0: 'w',
x1y1: 'b'
})
assert.deepEqual(alice3a._conflicts, {})
})
newChange (doc) {
if (this.previousDoc) {
const changes = Automerge.getChanges(this.previousDoc, doc)
changes
.filter(change => change.actor === this.actor)
.filter(change => !this.changes[change.seq])
.forEach(change => {
const {actor, seq, ...props} = change
this.changes[change.seq] = props
this.emit('change', change)
})
}
this.previousDoc = this.watchableDoc.get()
}
it(`2a. Alice's edit gets synced over to Bob's canvas`, () => {
const aliceChanges2a = Automerge.getChanges(alice1, alice2)
bob2a = Automerge.applyChanges(bob2, aliceChanges2a)
alice2a = alice2
assert.deepEqual(bob2a, {
_objectId: '00000000-0000-0000-0000-000000000000',
x0y0: 'r',
x0y1: 'w',
x1y0: 'w',
x1y1: 'w'
})
assert.deepEqual(bob2a._conflicts, {})
})
ops.forEach(op => {
const updatedDoc = Automerge.change(lastDoc, doc => applyOperation(doc.doc, op))
const changes = Automerge.getChanges(lastDoc, updatedDoc);
lastTransformed = transformer.apply(updatedDoc.doc, changes);
lastDoc = updatedDoc;
});
update(doc) {
this._ensureReady()
const actorId = this._getActorId(doc)
const docId = this._actorToId(actorId)
const pDoc = this.find(docId)
log('update', docId, actorId)
const changes = Automerge.getChanges(pDoc, doc)
.filter(({ actor }) => actor === actorId)
this._addToMaxRequested(docId, actorId, changes.length)
this._appendAll(actorId, changes)
this._set(docId, doc)
this.emit('document:updated', docId, doc)
this._handles(docId).forEach(handle => {
handle._update(doc)
})
return doc
}
update (doc) {
this._ensureReady()
const actorId = this.getActorId(doc)
const docId = this.actorToId(actorId)
const pDoc = this.find(docId)
const changes = Automerge.getChanges(pDoc, doc)
.filter(({actor}) => actor === actorId)
this._addToMaxRequested(docId, actorId, changes.length)
this._appendAll(actorId, changes)
this.pDocs[docId] = doc
return this.set(doc)
}
update (doc) {
this._ensureReady()
const hex = this.getHex(doc)
const docId = this.hexToId(hex)
const pDoc = this.find(docId)
const changes = Automerge.getChanges(pDoc, doc)
.filter(({actor}) => actor === hex)
this._addToMaxRequested(docId, hex, changes.length)
this._appendAll(hex, changes)
return this.set(doc)
}