From e3520ac711834fb5ca7b587ad5075ad054ecac27 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Sun, 7 Aug 2016 21:04:32 -0400 Subject: [PATCH] Coalesce adjacent patch actions from a given pid --- js/src/actor.js | 5 +---- js/src/dataspace.js | 9 +++++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/js/src/actor.js b/js/src/actor.js index d458f8f..4e767cc 100644 --- a/js/src/actor.js +++ b/js/src/actor.js @@ -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); }); }); } diff --git a/js/src/dataspace.js b/js/src/dataspace.js index 6d9af72..f892abc 100644 --- a/js/src/dataspace.js +++ b/js/src/dataspace.js @@ -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]); };