implement quill binding for y-text

This commit is contained in:
Kevin Jahns
2018-02-26 02:18:39 +01:00
parent da748a78f4
commit 248d08be30
17 changed files with 713 additions and 1090 deletions

View File

@@ -39,6 +39,11 @@ export function splitHelper (y, a, b, diff) {
o = o._right
}
y.os.put(b)
if (y._transaction.newTypes.has(a)) {
y._transaction.newTypes.add(b)
} else if (y._transaction.deletedStructs.has(a)) {
y._transaction.deletedStructs.add(b)
}
}
export default class Item {

31
src/Struct/ItemEmbed.js Normal file
View File

@@ -0,0 +1,31 @@
import { default as Item } from './Item.js'
import { logID } from '../MessageHandler/messageToString.js'
export default class ItemEmbed extends Item {
constructor () {
super()
this.embed = null
}
_copy (undeleteChildren, copyPosition) {
let struct = super._copy(undeleteChildren, copyPosition)
struct.embed = this.embed
return struct
}
get _length () {
return 1
}
_fromBinary (y, decoder) {
const missing = super._fromBinary(y, decoder)
this.embed = JSON.parse(decoder.readVarString())
return missing
}
_toBinary (encoder) {
super._toBinary(encoder)
encoder.writeVarString(JSON.stringify(this.embed))
}
_logString () {
const left = this._left !== null ? this._left._lastId : null
const origin = this._origin !== null ? this._origin._lastId : null
return `ItemEmbed(id:${logID(this._id)},embed:${JSON.stringify(this.embed)},left:${logID(left)},origin:${logID(origin)},right:${logID(this._right)},parent:${logID(this._parent)},parentSub:${this._parentSub})`
}
}

View File

@@ -1,7 +1,7 @@
import { default as Item } from './Item.js'
import { logID } from '../MessageHandler/messageToString.js'
export default class ItemString extends Item {
export default class ItemFormat extends Item {
constructor () {
super()
this.key = null
@@ -20,26 +20,19 @@ export default class ItemString extends Item {
return false
}
_fromBinary (y, decoder) {
let missing = super._fromBinary(y, decoder)
const missing = super._fromBinary(y, decoder)
this.key = decoder.readVarString()
this.value = decoder.readVarString()
this.value = JSON.parse(decoder.readVarString())
return missing
}
_toBinary (encoder) {
super._toBinary(encoder)
encoder.writeVarString(this.key)
encoder.writeVarString(this.value)
encoder.writeVarString(JSON.stringify(this.value))
}
_logString () {
const left = this._left !== null ? this._left._lastId : null
const origin = this._origin !== null ? this._origin._lastId : null
return `ItemFormat(id:${logID(this._id)},key:${JSON.stringify(this.key)},value:${JSON.stringify(this.value)},left:${logID(left)},origin:${logID(origin)},right:${logID(this._right)},parent:${logID(this._parent)},parentSub:${this._parentSub})`
}
_splitAt (y, diff) {
if (diff === 0) {
return this
} else {
return this._right
}
}
}