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) {
// successfully anchor then the status will be updated.
var ANCHORING_TIMEOUT = 500;
var anchoringAnnots = added.filter(metadata.isWaitingToAnchor);
if (anchoringAnnots.length) {
setTimeout(function () {
var statusUpdates = arrayUtil
.filterMap(anchoringAnnots, function (annot) {
return findByID(getState().annotations, annot.id);
})
.filter(metadata.isWaitingToAnchor)
.reduce((statusUpdates, orphan) => {
statusUpdates[orphan.$tag] = 'timeout';
return statusUpdates;
var anchoringIDs = added.filter(metadata.isWaitingToAnchor)
.map(ann => ann.id);
if (anchoringIDs.length > 0) {
setTimeout(() => {
// Find annotations which haven't yet been anchored in the document.
var anns = getState().annotations;
var annsStillAnchoring = anchoringIDs.map(id => findByID(anns, id))
.filter(ann => ann && metadata.isWaitingToAnchor(ann));
// Mark anchoring as timed-out for these annotations.
var anchorStatusUpdates = annsStillAnchoring.reduce((updates, ann) => {
updates[ann.$tag] = 'timeout';
return updates;
}, {});
dispatch(updateAnchorStatus(statusUpdates));
dispatch(updateAnchorStatus(anchorStatusUpdates));
}, 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