implement update logging
This commit is contained in:
parent
22aef63d8a
commit
072947c0bb
@ -65,6 +65,8 @@ export {
|
|||||||
encodeSnapshotV2,
|
encodeSnapshotV2,
|
||||||
decodeStateVector,
|
decodeStateVector,
|
||||||
decodeStateVectorV2,
|
decodeStateVectorV2,
|
||||||
|
logUpdate,
|
||||||
|
logUpdateV2,
|
||||||
isDeleted,
|
isDeleted,
|
||||||
isParentOf,
|
isParentOf,
|
||||||
equalSnapshots,
|
equalSnapshots,
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
import * as binary from 'lib0/binary.js'
|
import * as binary from 'lib0/binary.js'
|
||||||
import * as decoding from 'lib0/decoding.js'
|
import * as decoding from 'lib0/decoding.js'
|
||||||
import * as encoding from 'lib0/encoding.js'
|
import * as encoding from 'lib0/encoding.js'
|
||||||
|
import * as logging from 'lib0/logging.js'
|
||||||
import {
|
import {
|
||||||
createID,
|
createID,
|
||||||
readItemContent,
|
readItemContent,
|
||||||
@ -82,6 +83,26 @@ export class LazyStructReader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Uint8Array} update
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
export const logUpdate = update => logUpdateV2(update, UpdateDecoderV1)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Uint8Array} update
|
||||||
|
* @param {typeof UpdateDecoderV2 | typeof UpdateDecoderV1} [YDecoder]
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
export const logUpdateV2 = (update, YDecoder = UpdateDecoderV2) => {
|
||||||
|
const structs = []
|
||||||
|
const lazyDecoder = new LazyStructReader(new YDecoder(decoding.createDecoder(update)))
|
||||||
|
for (let curr = lazyDecoder.curr; curr !== null; curr = lazyDecoder.next()) {
|
||||||
|
structs.push(curr)
|
||||||
|
}
|
||||||
|
logging.print(structs)
|
||||||
|
}
|
||||||
|
|
||||||
export class LazyStructWriter {
|
export class LazyStructWriter {
|
||||||
/**
|
/**
|
||||||
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder
|
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder
|
||||||
|
@ -57,7 +57,11 @@ export const testMergeUpdatesWrongOrder = tc => {
|
|||||||
])
|
])
|
||||||
|
|
||||||
const targetState = Y.encodeStateAsUpdate(ydoc)
|
const targetState = Y.encodeStateAsUpdate(ydoc)
|
||||||
|
t.info('Target State: ')
|
||||||
|
Y.logUpdate(targetState)
|
||||||
;[wrongOrder, overlapping, separated].forEach((updates, i) => {
|
;[wrongOrder, overlapping, separated].forEach((updates, i) => {
|
||||||
|
t.info('State $' + i + ':')
|
||||||
|
Y.logUpdate(updates)
|
||||||
const merged = new Y.Doc()
|
const merged = new Y.Doc()
|
||||||
Y.applyUpdate(merged, updates)
|
Y.applyUpdate(merged, updates)
|
||||||
t.compareArrays(merged.getArray().toArray(), array.toArray())
|
t.compareArrays(merged.getArray().toArray(), array.toArray())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user