fixed all tests & proper diff /w attribution in nested deltas

This commit is contained in:
Kevin Jahns
2025-12-07 01:21:19 +01:00
parent 718362324a
commit b2df311fce
8 changed files with 87 additions and 29 deletions

View File

@@ -100,11 +100,10 @@ export const testYdocDiff = () => {
ydocUpdated.getMap('map').get('nested').insert(0, [1])
// @todo add custom attribution
const d = Y.diffDocsToDelta(ydocStart, ydocUpdated)
console.log('calculated diff', d.toJSON())
t.compare(d, delta.create()
.update('text', delta.create().retain(5).insert('world'))
.update('array', delta.create().retain(1).insert(['x']))
.update('map', delta.create().set('newk', 42).update('nested', delta.create().insert([1])))
.update('text', delta.create().retain(5).insert(' world', null, { insert: [] }))
.update('array', delta.create().retain(1).insert(['x'], null, { insert: [] }))
.update('map', delta.create().set('newk', 42, { insert: [] }).update('nested', delta.create().insert([1], null, { insert: [] })))
)
console.log(d.toJSON())
debugger
}

View File

@@ -37,6 +37,37 @@ export const testIterators = _tc => {
console.log(vals, entries, keys)
}
export const testNestedMapEvent = () => {
const ydoc = new Y.Doc()
const ymap = ydoc.getMap()
const ymapNested = ymap.set('nested', new Y.Map())
let called = 0
ymap.observeDeep((events, tr) => {
const event = events.find(event => event.target === ymap) || new Y.YEvent(ymap, tr, new Set())
const d = event.deltaDeep
called++
t.compare(d, delta.create().update('nested', delta.create().set('k', 'v')))
})
ymapNested.set('k', 'v')
t.assert(called === 1)
}
export const testNestedMapEvent2 = () => {
const ydoc = new Y.Doc()
const yarr = ydoc.getArray()
const ymapNested = new Y.Map()
yarr.insert(0, [ymapNested])
let called = 0
yarr.observeDeep((events, tr) => {
const event = events.find(event => event.target === yarr) || new Y.YEvent(yarr, tr, new Set())
const d = event.deltaDeep
called++
t.compare(d, delta.create().modify(delta.create().set('k', 'v')))
})
ymapNested.set('k', 'v')
t.assert(called === 1)
}
/**
* Computing event changes after transaction should result in an error. See yjs#539
*