fix first y-array test
This commit is contained in:
@@ -17,6 +17,18 @@ export default class DeleteStore extends Tree {
|
||||
var n = this.ds.findWithUpperBound(id)
|
||||
return n != null && n.id[0] === id[0] && id[1] < n.id[1] + n.len
|
||||
}
|
||||
applyMissingDeletesOnStruct (struct) {
|
||||
const strID = struct._id
|
||||
// find most right delete
|
||||
let n = this.findWithUpperBound(new ID(strID.user, strID.clock + struct.length - 1))
|
||||
if (n === null || n.id.user !== strID.user || n.id.clock + n.length <= strID.clock) {
|
||||
// struct is not deleted
|
||||
return null
|
||||
}
|
||||
// TODO:
|
||||
// * iterate to the right and apply new Delete's
|
||||
throw new Error('Not implemented!')
|
||||
}
|
||||
/*
|
||||
* Mark an operation as deleted. returns the deleted node
|
||||
*/
|
||||
|
||||
@@ -3,83 +3,61 @@ import RootID from '../Util/ID.js'
|
||||
import { getStruct } from '../Util/structReferences.js'
|
||||
|
||||
export default class OperationStore extends Tree {
|
||||
constructor (y) {
|
||||
super()
|
||||
this.y = y
|
||||
}
|
||||
get (id) {
|
||||
let struct = this.find(id)
|
||||
if (struct === null && id instanceof RootID) {
|
||||
let Constr = getStruct(id.type)
|
||||
struct = new Constr()
|
||||
struct._id = id
|
||||
struct._parent = this.y
|
||||
this.put(struct)
|
||||
}
|
||||
return struct
|
||||
}
|
||||
// Use getItem for structs with _length > 1
|
||||
getItem (id) {
|
||||
var item = this.findWithUpperBound(id)
|
||||
if (item == null) {
|
||||
if (item === null) {
|
||||
return null
|
||||
}
|
||||
var len = item.content != null ? item.content.length : 1 // in case of opContent
|
||||
if (id[0] === item.id[0] && id[1] < item.id[1] + len) {
|
||||
const itemID = item._id
|
||||
if (id.user === itemID.user && id.clock < itemID.clock + item._length) {
|
||||
return item
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
|
||||
}
|
||||
// Return an insertion such that id is the first element of content
|
||||
// This function manipulates an operation, if necessary
|
||||
getInsertionCleanStart (id) {
|
||||
var ins = this.getInsertion(id)
|
||||
if (ins != null) {
|
||||
if (ins.id[1] === id[1]) {
|
||||
return ins
|
||||
} else {
|
||||
var left = Y.utils.copyObject(ins)
|
||||
ins.content = left.content.splice(id[1] - ins.id[1])
|
||||
ins.id = id
|
||||
var leftLid = Y.utils.getLastId(left)
|
||||
ins.origin = leftLid
|
||||
left.originOf = [ins.id]
|
||||
left.right = ins.id
|
||||
ins.left = leftLid
|
||||
// debugger // check
|
||||
this.setOperation(left)
|
||||
this.setOperation(ins)
|
||||
if (left.gc) {
|
||||
this.store.queueGarbageCollector(ins.id)
|
||||
}
|
||||
return ins
|
||||
}
|
||||
// This function manipulates an item, if necessary
|
||||
getItemCleanStart (id) {
|
||||
var ins = this.getItem(id)
|
||||
if (ins === null || ins._length === 1) {
|
||||
return ins
|
||||
}
|
||||
const insID = ins._id
|
||||
if (insID.clock === id.clock) {
|
||||
return ins
|
||||
} else {
|
||||
return null
|
||||
return ins._splitAt(this.y, id.clock - insID.clock)
|
||||
}
|
||||
}
|
||||
// Return an insertion such that id is the last element of content
|
||||
// This function manipulates an operation, if necessary
|
||||
getInsertionCleanEnd (id) {
|
||||
var ins = this.getInsertion(id)
|
||||
if (ins != null) {
|
||||
if (ins.content == null || (ins.id[1] + ins.content.length - 1 === id[1])) {
|
||||
return ins
|
||||
} else {
|
||||
var right = Y.utils.copyObject(ins)
|
||||
right.content = ins.content.splice(id[1] - ins.id[1] + 1) // cut off remainder
|
||||
right.id = [id[0], id[1] + 1]
|
||||
var insLid = Y.utils.getLastId(ins)
|
||||
right.origin = insLid
|
||||
ins.originOf = [right.id]
|
||||
ins.right = right.id
|
||||
right.left = insLid
|
||||
// debugger // check
|
||||
this.setOperation(right)
|
||||
this.setOperation(ins)
|
||||
if (ins.gc) {
|
||||
this.store.queueGarbageCollector(right.id)
|
||||
}
|
||||
return ins
|
||||
}
|
||||
getItemCleanEnd (id) {
|
||||
var ins = this.getItem(id)
|
||||
if (ins === null || ins._length === 1) {
|
||||
return ins
|
||||
}
|
||||
const insID = ins._id
|
||||
if (insID.clock + ins._length - 1 === id.clock) {
|
||||
return ins
|
||||
} else {
|
||||
return null
|
||||
ins._splitAt(this.y, id.clock - insID.clock + 1)
|
||||
return ins
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user