fix first y-array test

This commit is contained in:
Kevin Jahns
2017-10-16 04:53:12 +02:00
parent 4eec8ecdd3
commit 1311c7a0d8
28 changed files with 489 additions and 284 deletions

View File

@@ -1,26 +1,44 @@
import StructManager from '../Util/StructManager.js'
import { getReference } from '../Util/structReferences.js'
export function deleteItemRange (y, user, clock, range) {
let items = y.os.getItems(this._target, this._length)
for (let i = items.length - 1; i >= 0; i--) {
items[i]._delete(y, false)
}
}
/**
* Delete is not a real struct. It will not be saved in OS
*/
export default class Delete {
constructor () {
this._target = null
this._targetID = null
this._length = null
}
_fromBinary (y, decoder) {
this._targetID = decoder.readOpID()
this._targetID = decoder.readID()
this._length = decoder.readVarUint()
}
_toBinary (y, encoder) {
encoder.writeUint8(StructManager.getReference(this.constructor))
encoder.writeOpID(this._targetID)
_toBinary (encoder) {
encoder.writeUint8(getReference(this.constructor))
encoder.writeID(this._targetID)
encoder.writeVarUint(this._length)
}
_integrate (y) {
let items = y.os.getItems(this._target, this._length)
for (let i = items.length - 1; i >= 0; i--) {
items[i]._delete()
/**
* - If created remotely (a remote user deleted something),
* this Delete is applied to all structs in id-range.
* - If created lokally (e.g. when y-array deletes a range of elements),
* this struct is broadcasted only (it is already executed)
*/
_integrate (y, locallyCreated = false) {
if (!locallyCreated) {
// from remote
const id = this._targetID
deleteItemRange(y, id.user, id.clock, this._length)
} else {
// from local
y.connector.broadcastStruct(this)
}
// TODO: only broadcast if created by local user or if y.connector._forwardAppliedStructs..
y.connector.broadcastStruct(this)
if (y.persistence !== null) {
y.persistence.saveOperations(this)
}