Merge 27299f7746a69dbc59354cd027069c502cdaddf2 into 3ecfb4e898076ff3cd4d83001be2721065c43acf
This commit is contained in:
commit
b4c1b9e5b1
@ -265,7 +265,10 @@ const integrateStructs = (transaction, store, clientsStructRefs) => {
|
|||||||
*/
|
*/
|
||||||
const updateMissingSv = (client, clock) => {
|
const updateMissingSv = (client, clock) => {
|
||||||
const mclock = missingSV.get(client)
|
const mclock = missingSV.get(client)
|
||||||
if (mclock == null || mclock > clock) {
|
if (mclock === undefined) {
|
||||||
|
// we never seen that client before
|
||||||
|
missingSV.set(client, 0)
|
||||||
|
} else if (mclock > clock) {
|
||||||
missingSV.set(client, clock)
|
missingSV.set(client, clock)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -327,3 +327,45 @@ export const testSyncDocsEvent = async _tc => {
|
|||||||
t.assert(!ydoc.isSynced)
|
t.assert(!ydoc.isSynced)
|
||||||
t.assert(ydoc.whenSynced !== oldWhenSynced)
|
t.assert(ydoc.whenSynced !== oldWhenSynced)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {t.TestCase} tc
|
||||||
|
*/
|
||||||
|
export const testMissingStateVector = tc => {
|
||||||
|
const d1 = new Y.Doc()
|
||||||
|
d1.clientID = 1
|
||||||
|
const m1 = d1.getMap('test')
|
||||||
|
/** @type {any[]} */
|
||||||
|
const updates = []
|
||||||
|
d1.on('update', (update) => {
|
||||||
|
updates.push(update)
|
||||||
|
})
|
||||||
|
m1.set('a', '1')
|
||||||
|
m1.set('b', '2')
|
||||||
|
m1.set('c', '3')
|
||||||
|
m1.set('d', '4')
|
||||||
|
m1.set('e', '5')
|
||||||
|
|
||||||
|
// we only apply second half of the updates
|
||||||
|
const second = updates.slice(3)
|
||||||
|
|
||||||
|
const d2 = new Y.Doc()
|
||||||
|
d2.clientID = 2
|
||||||
|
const m2 = d2.getMap('test')
|
||||||
|
|
||||||
|
for (let u of second) {
|
||||||
|
Y.applyUpdate(d2, u)
|
||||||
|
}
|
||||||
|
let json = m2.toJSON()
|
||||||
|
t.compare(json, {})
|
||||||
|
|
||||||
|
// a missing state vector should mark the beginning of missing updates
|
||||||
|
const missingSV = /** @type {Map<number, number>} */ (d2.store.pendingStructs?.missing)
|
||||||
|
//t.compare(missingSV, new Map([[1, 0]]))
|
||||||
|
|
||||||
|
// exchange all updates from missing state vector onwards
|
||||||
|
const update = Y.encodeStateAsUpdate(d1, Y.encodeStateVector(missingSV))
|
||||||
|
Y.applyUpdate(d2, update)
|
||||||
|
json = m2.toJSON()
|
||||||
|
t.compare(json, {'a':'1','b':'2','c':'3','d':'4','e':'5'})
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user