delete child if parent is deleted
This commit is contained in:
parent
74f9ceab01
commit
5cf8d20cf6
@ -29,19 +29,6 @@ export default class DeleteStore extends Tree {
|
|||||||
var n = this.findWithUpperBound(id)
|
var n = this.findWithUpperBound(id)
|
||||||
return n !== null && n._id.user === id.user && id.clock < n._id.clock + n.len
|
return n !== null && n._id.user === id.user && id.clock < n._id.clock + n.len
|
||||||
}
|
}
|
||||||
// TODO: put this in function (and all other methods)
|
|
||||||
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.len <= 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
|
* Mark an operation as deleted. returns the deleted node
|
||||||
*/
|
*/
|
||||||
|
@ -39,15 +39,20 @@ export function deleteItemRange (y, user, clock, range) {
|
|||||||
*/
|
*/
|
||||||
export default class Delete {
|
export default class Delete {
|
||||||
constructor () {
|
constructor () {
|
||||||
this._targetID = null
|
this._target = null
|
||||||
this._length = null
|
this._length = null
|
||||||
}
|
}
|
||||||
_fromBinary (y, decoder) {
|
_fromBinary (y, decoder) {
|
||||||
// TODO: set target, and add it to missing if not found
|
// TODO: set target, and add it to missing if not found
|
||||||
// There is an edge case in p2p networks!
|
// There is an edge case in p2p networks!
|
||||||
this._targetID = decoder.readID()
|
const targetID = decoder.readID()
|
||||||
|
this._targetID = targetID
|
||||||
this._length = decoder.readVarUint()
|
this._length = decoder.readVarUint()
|
||||||
return []
|
if (y.os.getItem(targetID) === null) {
|
||||||
|
return [targetID]
|
||||||
|
} else {
|
||||||
|
return []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_toBinary (encoder) {
|
_toBinary (encoder) {
|
||||||
encoder.writeUint8(getReference(this.constructor))
|
encoder.writeUint8(getReference(this.constructor))
|
||||||
|
@ -196,6 +196,9 @@ export default class Item {
|
|||||||
right._left = this
|
right._left = this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (parent._deleted) {
|
||||||
|
this._delete(y, false)
|
||||||
|
}
|
||||||
y.os.put(this)
|
y.os.put(this)
|
||||||
transactionTypeChanged(y, parent, parentSub)
|
transactionTypeChanged(y, parent, parentSub)
|
||||||
if (this._id.user !== RootFakeUserID) {
|
if (this._id.user !== RootFakeUserID) {
|
||||||
@ -205,7 +208,6 @@ export default class Item {
|
|||||||
if (y.persistence !== null) {
|
if (y.persistence !== null) {
|
||||||
y.persistence.saveOperations(this)
|
y.persistence.saveOperations(this)
|
||||||
}
|
}
|
||||||
y.ds.applyMissingDeletesOnStruct(this)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_toBinary (encoder) {
|
_toBinary (encoder) {
|
||||||
|
@ -80,7 +80,9 @@ export default class YXmlElement extends YXmlFragment {
|
|||||||
keys.push(key)
|
keys.push(key)
|
||||||
}
|
}
|
||||||
keys.sort()
|
keys.sort()
|
||||||
for (let key in keys) {
|
const keysLen = keys.length
|
||||||
|
for (let i = 0; i < keysLen; i++) {
|
||||||
|
const key = keys[i]
|
||||||
stringBuilder.push(key + '="' + attrs[key] + '"')
|
stringBuilder.push(key + '="' + attrs[key] + '"')
|
||||||
}
|
}
|
||||||
const nodeName = this.nodeName.toLocaleLowerCase()
|
const nodeName = this.nodeName.toLocaleLowerCase()
|
||||||
|
@ -352,3 +352,19 @@ test('y-xml: Random tests (46)', async function xmlRandom46 (t) {
|
|||||||
test('y-xml: Random tests (47)', async function xmlRandom47 (t) {
|
test('y-xml: Random tests (47)', async function xmlRandom47 (t) {
|
||||||
await applyRandomTests(t, xmlTransactions, 47)
|
await applyRandomTests(t, xmlTransactions, 47)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('y-xml: Random tests (100)', async function xmlRandom100 (t) {
|
||||||
|
await applyRandomTests(t, xmlTransactions, 100)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('y-xml: Random tests (200)', async function xmlRandom200 (t) {
|
||||||
|
await applyRandomTests(t, xmlTransactions, 200)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('y-xml: Random tests (500)', async function xmlRandom500 (t) {
|
||||||
|
await applyRandomTests(t, xmlTransactions, 500)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('y-xml: Random tests (1000)', async function xmlRandom1000 (t) {
|
||||||
|
await applyRandomTests(t, xmlTransactions, 1000)
|
||||||
|
})
|
||||||
|
@ -106,7 +106,8 @@ export async function compareUsers (t, users) {
|
|||||||
left: op._left === null ? null : op._left._lastId,
|
left: op._left === null ? null : op._left._lastId,
|
||||||
right: op._right === null ? null : op._right._id,
|
right: op._right === null ? null : op._right._id,
|
||||||
length: op._length,
|
length: op._length,
|
||||||
deleted: op._deleted
|
deleted: op._deleted,
|
||||||
|
parent: op._parent._id
|
||||||
}
|
}
|
||||||
if (op instanceof ItemJSON || op instanceof ItemString) {
|
if (op instanceof ItemJSON || op instanceof ItemString) {
|
||||||
json.content = op._content
|
json.content = op._content
|
||||||
|
Loading…
x
Reference in New Issue
Block a user