all YArray.tests type fixes

This commit is contained in:
Kevin Jahns
2019-04-03 02:30:44 +02:00
parent e23582b1cd
commit 415de1cc4c
17 changed files with 383 additions and 180 deletions

View File

@@ -25,6 +25,9 @@ export class ItemJSON extends AbstractItem {
*/
constructor (id, left, right, parent, parentSub, content) {
super(id, left, right, parent, parentSub)
/**
* @type {Array<any>}
*/
this.content = content
}
/**
@@ -56,6 +59,17 @@ export class ItemJSON extends AbstractItem {
right.content = this.content.splice(diff)
return right
}
/**
* @param {ItemJSON} right
* @return {boolean}
*/
mergeWith (right) {
if (right.origin === this && this.right === right) {
this.content = this.content.concat(right.content)
return true
}
return false
}
/**
* @param {encoding.Encoder} encoder
* @param {number} offset
@@ -63,8 +77,8 @@ export class ItemJSON extends AbstractItem {
write (encoder, offset) {
super.write(encoder, offset, structJSONRefNumber)
const len = this.content.length
encoding.writeVarUint(encoder, len)
for (let i = 0; i < len; i++) {
encoding.writeVarUint(encoder, len - offset)
for (let i = offset; i < len; i++) {
const c = this.content[i]
encoding.writeVarString(encoder, c === undefined ? 'undefined' : JSON.stringify(c))
}