mirror of
https://github.com/yjs/yjs.git
synced 2026-01-09 07:48:01 -05:00
fixed all tests & proper diff /w attribution in nested deltas
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user