Files
yjs/src/structs/ItemEmbed.js

50 lines
1.2 KiB
JavaScript
Raw Normal View History

/**
2018-11-25 03:17:00 +01:00
* @module structs
*/
2018-02-26 02:18:39 +01:00
2018-11-27 14:59:12 +01:00
import { Item } from './Item.js'
2019-03-01 23:26:40 +01:00
import * as stringify from 'y-protocols/utils/structStringify.js'
2019-03-10 23:26:53 +01:00
import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.js'
2018-11-27 14:59:12 +01:00
import { Y } from '../utils/Y.js' // eslint-disable-line
2018-11-25 03:17:00 +01:00
export class ItemEmbed extends Item {
2018-02-26 02:18:39 +01:00
constructor () {
super()
this.embed = null
}
_copy (undeleteChildren, copyPosition) {
let struct = super._copy()
2018-02-26 02:18:39 +01:00
struct.embed = this.embed
return struct
}
get _length () {
return 1
}
/**
* @param {Y} y
* @param {decoding.Decoder} decoder
*/
2018-02-26 02:18:39 +01:00
_fromBinary (y, decoder) {
const missing = super._fromBinary(y, decoder)
this.embed = JSON.parse(decoding.readVarString(decoder))
2018-02-26 02:18:39 +01:00
return missing
}
/**
* @param {encoding.Encoder} encoder
*/
2018-02-26 02:18:39 +01:00
_toBinary (encoder) {
super._toBinary(encoder)
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 () {
return stringify.logItemHelper('ItemEmbed', this, `embed:${JSON.stringify(this.embed)}`)
2018-02-26 02:18:39 +01:00
}
}