2018-10-08 17:08:20 +02:00
|
|
|
import Item from './Item.js'
|
2018-11-09 00:13:30 +01:00
|
|
|
import { logItemHelper } from '../protocols/syncProtocol.js'
|
2018-10-29 21:58:21 +01:00
|
|
|
import * as encoding from '../../lib/encoding.js'
|
|
|
|
|
import * as decoding from '../../lib/decoding.js'
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @typedef {import('../index.js').Y} Y
|
|
|
|
|
*/
|
2018-02-26 02:18:39 +01:00
|
|
|
|
|
|
|
|
export default class ItemEmbed extends Item {
|
|
|
|
|
constructor () {
|
|
|
|
|
super()
|
|
|
|
|
this.embed = null
|
|
|
|
|
}
|
|
|
|
|
_copy (undeleteChildren, copyPosition) {
|
2018-10-29 21:58:21 +01:00
|
|
|
let struct = super._copy()
|
2018-02-26 02:18:39 +01:00
|
|
|
struct.embed = this.embed
|
|
|
|
|
return struct
|
|
|
|
|
}
|
|
|
|
|
get _length () {
|
|
|
|
|
return 1
|
|
|
|
|
}
|
2018-10-29 21:58:21 +01:00
|
|
|
/**
|
|
|
|
|
* @param {Y} y
|
|
|
|
|
* @param {decoding.Decoder} decoder
|
|
|
|
|
*/
|
2018-02-26 02:18:39 +01:00
|
|
|
_fromBinary (y, decoder) {
|
|
|
|
|
const missing = super._fromBinary(y, decoder)
|
2018-10-29 21:58:21 +01:00
|
|
|
this.embed = JSON.parse(decoding.readVarString(decoder))
|
2018-02-26 02:18:39 +01:00
|
|
|
return missing
|
|
|
|
|
}
|
2018-10-29 21:58:21 +01:00
|
|
|
/**
|
|
|
|
|
* @param {encoding.Encoder} encoder
|
|
|
|
|
*/
|
2018-02-26 02:18:39 +01:00
|
|
|
_toBinary (encoder) {
|
|
|
|
|
super._toBinary(encoder)
|
2018-10-29 21:58:21 +01:00
|
|
|
encoding.writeVarString(encoder, JSON.stringify(this.embed))
|
2018-02-26 02:18:39 +01:00
|
|
|
}
|
2018-03-29 11:58:02 +02:00
|
|
|
/**
|
|
|
|
|
* Transform this YXml Type to a readable format.
|
|
|
|
|
* Useful for logging as all Items and Delete implement this method.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
2018-02-26 02:18:39 +01:00
|
|
|
_logString () {
|
2018-03-29 11:58:02 +02:00
|
|
|
return logItemHelper('ItemEmbed', this, `embed:${JSON.stringify(this.embed)}`)
|
2018-02-26 02:18:39 +01:00
|
|
|
}
|
|
|
|
|
}
|