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

@@ -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)
}
}
}