mergeUpdates on array with single entry just returns the first entry

This commit is contained in:
Kevin Jahns 2021-09-23 22:14:29 +02:00
parent 633eb9033c
commit f1ab417570

@ -287,6 +287,9 @@ const sliceStruct = (left, diff) => {
* @return {Uint8Array} * @return {Uint8Array}
*/ */
export const mergeUpdatesV2 = (updates, YDecoder = UpdateDecoderV2, YEncoder = UpdateEncoderV2) => { export const mergeUpdatesV2 = (updates, YDecoder = UpdateDecoderV2, YEncoder = UpdateEncoderV2) => {
if (updates.length === 1) {
return updates[0]
}
const updateDecoders = updates.map(update => new YDecoder(decoding.createDecoder(update))) const updateDecoders = updates.map(update => new YDecoder(decoding.createDecoder(update)))
let lazyStructDecoders = updateDecoders.map(decoder => new LazyStructReader(decoder, true)) let lazyStructDecoders = updateDecoders.map(decoder => new LazyStructReader(decoder, true))
@ -312,8 +315,9 @@ export const mergeUpdatesV2 = (updates, YDecoder = UpdateDecoderV2, YEncoder = U
if (dec1.curr.id.client === dec2.curr.id.client) { if (dec1.curr.id.client === dec2.curr.id.client) {
const clockDiff = dec1.curr.id.clock - dec2.curr.id.clock const clockDiff = dec1.curr.id.clock - dec2.curr.id.clock
if (clockDiff === 0) { if (clockDiff === 0) {
// @todo remove references to skip since the structDecoders must filter Skips.
return dec1.curr.constructor === dec2.curr.constructor ? 0 : ( return dec1.curr.constructor === dec2.curr.constructor ? 0 : (
dec1.curr.constructor === Skip ? 1 : -1 dec1.curr.constructor === Skip ? 1 : -1 // we are filtering skips anyway.
) )
} else { } else {
return clockDiff return clockDiff