basic merge works. fixes first test #263
This commit is contained in:
parent
c8534ea6bc
commit
004a781a56
@ -639,6 +639,10 @@ export class Item extends AbstractStruct {
|
|||||||
}
|
}
|
||||||
if (origin === null && rightOrigin === null) {
|
if (origin === null && rightOrigin === null) {
|
||||||
const parent = /** @type {AbstractType<any>} */ (this.parent)
|
const parent = /** @type {AbstractType<any>} */ (this.parent)
|
||||||
|
if (parent.constructor === String) { // this edge case was added by differential updates
|
||||||
|
encoder.writeParentInfo(true) // write parentYKey
|
||||||
|
encoder.writeString(parent)
|
||||||
|
} else {
|
||||||
const parentItem = parent._item
|
const parentItem = parent._item
|
||||||
if (parentItem === null) {
|
if (parentItem === null) {
|
||||||
// parent type on y._map
|
// parent type on y._map
|
||||||
@ -650,6 +654,7 @@ export class Item extends AbstractStruct {
|
|||||||
encoder.writeParentInfo(false) // write parent id
|
encoder.writeParentInfo(false) // write parent id
|
||||||
encoder.writeLeftID(parentItem.id)
|
encoder.writeLeftID(parentItem.id)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (parentSub !== null) {
|
if (parentSub !== null) {
|
||||||
encoder.writeString(parentSub)
|
encoder.writeString(parentSub)
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,6 @@ export class LazyStructWriter {
|
|||||||
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder
|
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder
|
||||||
*/
|
*/
|
||||||
constructor (encoder) {
|
constructor (encoder) {
|
||||||
this.fresh = true
|
|
||||||
/**
|
/**
|
||||||
* We keep the last written struct around in case we want to
|
* We keep the last written struct around in case we want to
|
||||||
* merge it with the next written struct.
|
* merge it with the next written struct.
|
||||||
@ -107,7 +106,7 @@ export class LazyStructWriter {
|
|||||||
* @param {Array<Uint8Array>} updates
|
* @param {Array<Uint8Array>} updates
|
||||||
* @return {Uint8Array}
|
* @return {Uint8Array}
|
||||||
*/
|
*/
|
||||||
export const mergeUpdates = updates => mergeUpdatesV2(updates, UpdateDecoderV1, UpdateEncoderV2)
|
export const mergeUpdates = updates => mergeUpdatesV2(updates, UpdateDecoderV1, UpdateEncoderV1)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is intended to slice any kind of struct and retrieve the right part.
|
* This method is intended to slice any kind of struct and retrieve the right part.
|
||||||
@ -213,6 +212,10 @@ export const mergeUpdatesV2 = (updates, YDecoder = UpdateDecoderV2, YEncoder = U
|
|||||||
currWrite = { struct: next, offset: 0 }
|
currWrite = { struct: next, offset: 0 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (currWrite !== null) {
|
||||||
|
writeStructToLazyStructWriter(lazyStructEncoder, currWrite.struct, currWrite.offset)
|
||||||
|
currWrite = null
|
||||||
|
}
|
||||||
finishLazyStructWriting(lazyStructEncoder)
|
finishLazyStructWriting(lazyStructEncoder)
|
||||||
|
|
||||||
const dss = updateDecoders.map(decoder => readDeleteSet(decoder))
|
const dss = updateDecoders.map(decoder => readDeleteSet(decoder))
|
||||||
@ -233,10 +236,10 @@ export const diffUpdate = (update, sv) => {
|
|||||||
* @param {LazyStructWriter} lazyWriter
|
* @param {LazyStructWriter} lazyWriter
|
||||||
*/
|
*/
|
||||||
const flushLazyStructWriter = lazyWriter => {
|
const flushLazyStructWriter = lazyWriter => {
|
||||||
if (!lazyWriter.fresh) {
|
if (lazyWriter.written > 0) {
|
||||||
lazyWriter.clientStructs.push({ written: lazyWriter.written, restEncoder: encoding.toUint8Array(lazyWriter.encoder.restEncoder) })
|
lazyWriter.clientStructs.push({ written: lazyWriter.written, restEncoder: encoding.toUint8Array(lazyWriter.encoder.restEncoder) })
|
||||||
lazyWriter.encoder.restEncoder = encoding.createEncoder()
|
lazyWriter.encoder.restEncoder = encoding.createEncoder()
|
||||||
lazyWriter.fresh = true
|
lazyWriter.written = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,8 +250,10 @@ const flushLazyStructWriter = lazyWriter => {
|
|||||||
*/
|
*/
|
||||||
const writeStructToLazyStructWriter = (lazyWriter, struct, offset) => {
|
const writeStructToLazyStructWriter = (lazyWriter, struct, offset) => {
|
||||||
// flush curr if we start another client
|
// flush curr if we start another client
|
||||||
if (!lazyWriter.fresh && lazyWriter.currClient !== struct.id.client) {
|
if (lazyWriter.written > 0 && lazyWriter.currClient !== struct.id.client) {
|
||||||
flushLazyStructWriter(lazyWriter)
|
flushLazyStructWriter(lazyWriter)
|
||||||
|
}
|
||||||
|
if (lazyWriter.written === 0) {
|
||||||
lazyWriter.currClient = struct.id.client
|
lazyWriter.currClient = struct.id.client
|
||||||
// write next client
|
// write next client
|
||||||
lazyWriter.encoder.writeClient(struct.id.client)
|
lazyWriter.encoder.writeClient(struct.id.client)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user