Better pendingPatch logic

This commit is contained in:
Tony Garnock-Jones 2016-08-07 22:50:12 -04:00
parent 7df50fbac9
commit 3de86c3b29
1 changed files with 13 additions and 11 deletions

View File

@ -219,19 +219,21 @@ Dataspace.prototype.flushPendingPatch = function () {
};
Dataspace.prototype.enqueueAction = function (pid, action) {
if (action.type === 'stateChange') {
if (!this.pendingPatch) {
this.pendingPatch = [pid, action.patch];
return;
}
if (this.pendingPatch[0] === pid) {
this.pendingPatch[1] = this.pendingPatch[1].andThen(action.patch);
return;
}
/* fall through */
if (action.type === 'stateChange' && this.pendingPatch && this.pendingPatch[0] === pid) {
this.pendingPatch[1] = this.pendingPatch[1].andThen(action.patch);
return;
}
// If we get here, any pendingPatch that might exist is definitely
// not something we can extend, but it has to happen before action,
// so flush it now.
this.flushPendingPatch();
this.pendingActions = this.pendingActions.push([pid, action]);
if (action.type === 'stateChange') {
this.pendingPatch = [pid, action.patch];
} else {
this.pendingActions = this.pendingActions.push([pid, action]);
}
};
Dataspace.prototype.dispatchActions = function () {