Commit 0c5fca98 authored by Robert Knight's avatar Robert Knight

Rewrite the anchoring timeout handling code for clarity

Respond to CR feedback that the function of this code was unclear.
parent d0c1e748
...@@ -261,19 +261,21 @@ function addAnnotations(annotations, now) { ...@@ -261,19 +261,21 @@ function addAnnotations(annotations, now) {
// successfully anchor then the status will be updated. // successfully anchor then the status will be updated.
var ANCHORING_TIMEOUT = 500; var ANCHORING_TIMEOUT = 500;
var anchoringAnnots = added.filter(metadata.isWaitingToAnchor); var anchoringIDs = added.filter(metadata.isWaitingToAnchor)
if (anchoringAnnots.length) { .map(ann => ann.id);
setTimeout(function () { if (anchoringIDs.length > 0) {
var statusUpdates = arrayUtil setTimeout(() => {
.filterMap(anchoringAnnots, function (annot) { // Find annotations which haven't yet been anchored in the document.
return findByID(getState().annotations, annot.id); var anns = getState().annotations;
}) var annsStillAnchoring = anchoringIDs.map(id => findByID(anns, id))
.filter(metadata.isWaitingToAnchor) .filter(ann => ann && metadata.isWaitingToAnchor(ann));
.reduce((statusUpdates, orphan) => {
statusUpdates[orphan.$tag] = 'timeout'; // Mark anchoring as timed-out for these annotations.
return statusUpdates; var anchorStatusUpdates = annsStillAnchoring.reduce((updates, ann) => {
updates[ann.$tag] = 'timeout';
return updates;
}, {}); }, {});
dispatch(updateAnchorStatus(statusUpdates)); dispatch(updateAnchorStatus(anchorStatusUpdates));
}, ANCHORING_TIMEOUT); }, ANCHORING_TIMEOUT);
} }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment