changed the observe functionality

This commit is contained in:
Kevin Jahns 2016-04-25 16:32:45 +02:00
parent 71bf6438e1
commit 6b8ce0ab4f
5 changed files with 32 additions and 17 deletions

View File

@ -179,6 +179,14 @@ If you want to see an issue fixed, please subscribe to the thread (or remind me
## Changelog
### 11.0.0
* **All types now return a single event instead of list of events**
* Insert events contain a list of values
* Improved performance for large insertions & deletions
* Several bugfixes (offline editing related)
* Native support for node 4 (see #49)
### 10.0.0
* Support for more complex types (a type can be a composition of several types)

View File

@ -74,8 +74,14 @@ function getRandomNumber (n) {
g.getRandomNumber = getRandomNumber
function getRandomString () {
var tokens = 'abcdefäö' // ü\n\n\n\n\n\n\n'
return tokens[getRandomNumber(tokens.length)]
var chars = 'abcdefäö'
var char = chars[getRandomNumber(chars.length)] // ü\n\n\n\n\n\n\n'
var length = getRandomNumber(7)
var string = ''
for (var i = 0; i < length; i++) {
string += char
}
return string
}
g.getRandomString = getRandomString

View File

@ -245,11 +245,12 @@ module.exports = function (Y/* :any */) {
}
// is a child of a map struct.
// Then also make sure that only the most left element is not deleted
// We do not call the type in this case (this is what the third parameter is for)
if (op.right != null) {
yield* this.deleteOperation(op.right, 1)
yield* this.deleteOperation(op.right, 1, true)
}
if (op.left != null) {
yield* this.deleteOperation(op.id, 1)
yield* this.deleteOperation(op.id, 1, true)
}
} else {
if (right == null || left == null) {

View File

@ -174,7 +174,7 @@ module.exports = function (Y/* :any */) {
/*
Mark an operation as deleted, and add it to the GC, if possible.
*/
* deleteOperation (targetId, length) /* :Generator<any, any, any> */ {
* deleteOperation (targetId, length, preventCallType) /* :Generator<any, any, any> */ {
if (length == null) {
length = 1
}
@ -253,7 +253,7 @@ module.exports = function (Y/* :any */) {
} else {
right = null
}
if (callType) {
if (callType && !preventCallType) {
var type = this.store.initializedTypes[JSON.stringify(target.parent)]
if (type != null) {
yield* type._changed(this, {

View File

@ -91,9 +91,9 @@ module.exports = function (Y /* : any*/) {
*/
receivedOp (op) {
if (this.awaiting <= 0) {
this.onevent([op])
this.onevent(op)
} else {
this.waiting.push(Y.utils.copyObject(op))
this.waiting.push(op)
}
}
/*
@ -102,8 +102,8 @@ module.exports = function (Y /* : any*/) {
prematurely called operations are executed
*/
awaitAndPrematurelyCall (ops) {
this.awaiting++
this.onevent(ops)
this.awaiting += ops.length
ops.forEach(this.onevent)
}
/*
Call this when you successfully awaited the execution of n Insert operations
@ -132,7 +132,7 @@ module.exports = function (Y /* : any*/) {
throw new Error('Expected Insert Operation!')
}
}
this._tryCallEvents()
this._tryCallEvents(n)
}
/*
Call this when you successfully awaited the execution of n Delete operations
@ -155,17 +155,17 @@ module.exports = function (Y /* : any*/) {
throw new Error('Expected Delete Operation!')
}
}
this._tryCallEvents()
this._tryCallEvents(n)
}
/* (private)
Try to execute the events for the waiting operations
*/
_tryCallEvents () {
this.awaiting--
if (this.awaiting <= 0 && this.waiting.length > 0) {
var events = this.waiting
_tryCallEvents (n) {
this.awaiting -= n
if (this.awaiting === 0 && this.waiting.length > 0) {
var ops = this.waiting
this.waiting = []
this.onevent(events)
ops.forEach(this.onevent)
}
}
}