Skip to content
This repository has been archived by the owner on May 12, 2020. It is now read-only.

Commit

Permalink
Add OperationRouter.getHasLocalUnsyncedOpsAndUpdates/OperationRouter.…
Browse files Browse the repository at this point in the history
…unsubscribeHasLocalUnsyncedOpsUpdates
  • Loading branch information
Friedrich W. H. Kossebau committed Dec 3, 2013
1 parent cba6073 commit 33c0a58
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
9 changes: 9 additions & 0 deletions programs/editor/server/nowjs/OperationRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,14 @@ define("webodf/editor/server/nowjs/OperationRouter", [], function () {
cb();
};
/*jslint emptyblock: false, unparam: false*/

this.getHasLocalUnsyncedOpsAndUpdates = function (subscriber) {
subscriber(false);
};

/*jslint emptyblock: true, unparam: true*/
this.unsubscribeHasLocalUnsyncedOpsUpdates = function (subscriber) {
};
/*jslint emptyblock: false, unparam: false*/
};
});
43 changes: 42 additions & 1 deletion programs/editor/server/pullbox/OperationRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ define("webodf/editor/server/pullbox/OperationRouter", [], function () {
unplayedServerOpspecQueue = [],
/** @type {!Array.<!Function>} sync request callbacks which should be called after the received ops have been applied server */
uncalledSyncRequestCallbacksQueue = [],
/** @type {!Array.<!function(!boolean):undefined>} ops created since the last sync call to the server */
hasLocalUnsyncedOpsStateSubscribers = [],
/**@type{!boolean}*/
hasLocalUnsyncedOps = false,
/**@type{!boolean} tells if any local ops have been modifying ops */
Expand All @@ -84,14 +86,18 @@ define("webodf/editor/server/pullbox/OperationRouter", [], function () {
* @return {undefined}
*/
function updateHasLocalUnsyncedOpsState() {
var hasLocalUnsyncedOpsNow = (unsyncedClientOpspecQueue.length > 0);
var i,
hasLocalUnsyncedOpsNow = (unsyncedClientOpspecQueue.length > 0);

// no change?
if (hasLocalUnsyncedOps === hasLocalUnsyncedOpsNow) {
return;
}

hasLocalUnsyncedOps = hasLocalUnsyncedOpsNow;
for (i=0; i<hasLocalUnsyncedOpsStateSubscribers.length; i+=1) {
hasLocalUnsyncedOpsStateSubscribers[i](hasLocalUnsyncedOps);
}
}

/**
Expand Down Expand Up @@ -454,5 +460,40 @@ runtime.log("OperationRouter: instant opsSync requested");
}
};

this.getHasLocalUnsyncedOpsAndUpdates = function (subscriber) {
var i;

// detect double subscription
for (i=0; i<hasLocalUnsyncedOpsStateSubscribers.length; i+=1) {
if (subscribers[i] === subscriber) {
break;
}
}
if (i < hasLocalUnsyncedOpsStateSubscribers.length) {
// already subscribed
runtime.log("double subscription request in PullBoxMemberModel::getHasLocalUnsyncedOpsAndUpdates");
} else {
// subscribe
hasLocalUnsyncedOpsStateSubscribers.push(subscriber);
}

subscriber(hasLocalUnsyncedOps);
};

/*jslint emptyblock: true, unparam: true*/
this.unsubscribeHasLocalUnsyncedOpsUpdates = function (subscriber) {
var i;

for (i=0; i<hasLocalUnsyncedOpsStateSubscribers.length; i+=1) {
if (hasLocalUnsyncedOpsStateSubscribers[i] === subscriber) {
break;
}
}

runtime.assert((i < hasLocalUnsyncedOpsStateSubscribers.length),
"tried to unsubscribe when not subscribed in PullBoxMemberModel::getHasLocalUnsyncedOpsAndUpdates");

hasLocalUnsyncedOpsStateSubscribers.splice(i,1);
};
};
});
17 changes: 17 additions & 0 deletions webodf/lib/ops/OperationRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,20 @@ ops.OperationRouter.prototype.push = function (operations) {"use strict"; };
* @return {undefined}
*/
ops.OperationRouter.prototype.close = function (callback) {"use strict"; };

/**
* subscriber is called with the current state and after that
* on every state change.
*
* @param {function(!boolean)} subscriber
* @return {undefined}
*/
ops.OperationRouter.prototype.getHasLocalUnsyncedOpsAndUpdates = function (subscriber) {"use strict"; };

/**
* Undoes the subscription done with getHasLocalUnsyncedOpsAndUpdates
*
* @param {function(!boolean)} subscriber
* @return {undefined}
*/
ops.OperationRouter.prototype.unsubscribeHasLocalUnsyncedOpsUpdates = function (subscriber) {"use strict"; };
9 changes: 9 additions & 0 deletions webodf/lib/ops/TrivialOperationRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,13 @@ ops.TrivialOperationRouter = function TrivialOperationRouter() {
this.close = function (cb) {
cb();
};

this.getHasLocalUnsyncedOpsAndUpdates = function (subscriber) {
subscriber(false);
};

/*jslint emptyblock: true, unparam: true*/
this.unsubscribeHasLocalUnsyncedOpsUpdates = function (subscriber) {
};
/*jslint emptyblock: false, unparam: false*/
};

0 comments on commit 33c0a58

Please sign in to comment.