108 lines
1.7 KiB
JavaScript
108 lines
1.7 KiB
JavaScript
|
|
import {
|
|
addToDeleteSet,
|
|
StructStore, Item, Transaction // eslint-disable-line
|
|
} from '../internals.js'
|
|
|
|
import * as encoding from 'lib0/encoding.js'
|
|
import * as decoding from 'lib0/decoding.js'
|
|
|
|
/**
|
|
* @private
|
|
*/
|
|
export class ContentDeleted {
|
|
/**
|
|
* @param {number} len
|
|
*/
|
|
constructor (len) {
|
|
this.len = len
|
|
}
|
|
|
|
/**
|
|
* @return {number}
|
|
*/
|
|
getLength () {
|
|
return this.len
|
|
}
|
|
|
|
/**
|
|
* @return {Array<any>}
|
|
*/
|
|
getContent () {
|
|
return []
|
|
}
|
|
|
|
/**
|
|
* @return {boolean}
|
|
*/
|
|
isCountable () {
|
|
return false
|
|
}
|
|
|
|
/**
|
|
* @return {ContentDeleted}
|
|
*/
|
|
copy () {
|
|
return new ContentDeleted(this.len)
|
|
}
|
|
|
|
/**
|
|
* @param {number} offset
|
|
* @return {ContentDeleted}
|
|
*/
|
|
splice (offset) {
|
|
const right = new ContentDeleted(this.len - offset)
|
|
this.len = offset
|
|
return right
|
|
}
|
|
|
|
/**
|
|
* @param {ContentDeleted} right
|
|
* @return {boolean}
|
|
*/
|
|
mergeWith (right) {
|
|
this.len += right.len
|
|
return true
|
|
}
|
|
|
|
/**
|
|
* @param {Transaction} transaction
|
|
* @param {Item} item
|
|
*/
|
|
integrate (transaction, item) {
|
|
addToDeleteSet(transaction.deleteSet, item.id, this.len)
|
|
item.deleted = true
|
|
}
|
|
|
|
/**
|
|
* @param {Transaction} transaction
|
|
*/
|
|
delete (transaction) {}
|
|
/**
|
|
* @param {StructStore} store
|
|
*/
|
|
gc (store) {}
|
|
/**
|
|
* @param {encoding.Encoder} encoder
|
|
* @param {number} offset
|
|
*/
|
|
write (encoder, offset) {
|
|
encoding.writeVarUint(encoder, this.len - offset)
|
|
}
|
|
|
|
/**
|
|
* @return {number}
|
|
*/
|
|
getRef () {
|
|
return 1
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
*
|
|
* @param {decoding.Decoder} decoder
|
|
* @return {ContentDeleted}
|
|
*/
|
|
export const readContentDeleted = decoder => new ContentDeleted(decoding.readVarUint(decoder))
|