Coalesce adjacent patch actions from a given pid

This commit is contained in:
Tony Garnock-Jones 2016-08-07 21:04:32 -04:00
parent 2c78d1ad0a
commit e3520ac711
2 changed files with 10 additions and 4 deletions

View File

@ -86,12 +86,9 @@ Actor.prototype.quiesce = function() {
var facet = subjectId[0];
var endpoint = subjectId[1];
withCurrentFacet(facet, function () {
// TODO: coalesce patches within a single actor
var aggregate = Patch.emptyPatch;
var patch = Patch.retract(__).andThen(endpoint.subscriptionFn.call(facet.fields));
var r = facet.actor.mux.updateStream(endpoint.eid, patch);
aggregate = aggregate.andThen(r.deltaAggregate);
Dataspace.stateChange(aggregate);
Dataspace.stateChange(r.deltaAggregate);
});
});
}

View File

@ -203,6 +203,15 @@ Dataspace.prototype.step = function () {
};
Dataspace.prototype.enqueueAction = function (pid, action) {
if (action.type === 'stateChange') {
var newestEntry = this.pendingActions.last();
if (newestEntry && newestEntry[0] === pid && newestEntry[1].type === 'stateChange') {
var combinedPatch = newestEntry[1].patch.andThen(action.patch);
this.pendingActions = this.pendingActions.pop().push([pid, stateChange(combinedPatch)]);
return;
}
/* fall through */
}
this.pendingActions = this.pendingActions.push([pid, action]);
};