From a772808e04d0211cf998e69ce9f98b5fd70ea302 Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Fri, 3 May 2019 13:23:24 -0700 Subject: [PATCH] Remove cacheing of disabled state for certain operations to avoid stale state (close #6296) --- modules/operations/circularize.js | 17 ++++++++--------- modules/operations/move.js | 12 +++++------- modules/operations/orthogonalize.js | 22 ++++++++++------------ modules/operations/reflect.js | 13 ++++++------- modules/operations/rotate.js | 12 +++++------- 5 files changed, 34 insertions(+), 42 deletions(-) diff --git a/modules/operations/circularize.js b/modules/operations/circularize.js index 3cccd08c8..a3bb66685 100644 --- a/modules/operations/circularize.js +++ b/modules/operations/circularize.js @@ -16,7 +16,6 @@ export function operationCircularize(selectedIDs, context) { }; var nodes = utilGetAllNodes(selectedIDs, context.graph()); var coords = nodes.map(function(n) { return n.loc; }); - var _disabled; var operation = function() { context.perform(action, operation.annotation()); @@ -30,21 +29,21 @@ export function operationCircularize(selectedIDs, context) { }; + // don't cache this because the visible extent could change operation.disabled = function() { - if (_disabled !== undefined) return _disabled; - _disabled = action.disabled(context.graph()); - if (_disabled) { - return _disabled; + var actionDisabled = action.disabled(context.graph()); + if (actionDisabled) { + return actionDisabled; } else if (extent.percentContainedIn(context.extent()) < 0.8) { - return _disabled = 'too_large'; + return 'too_large'; } else if (someMissing()) { - return _disabled = 'not_downloaded'; + return 'not_downloaded'; } else if (selectedIDs.some(context.hasHiddenConnections)) { - return _disabled = 'connected_to_hidden'; + return 'connected_to_hidden'; } - return _disabled = false; + return false; function someMissing() { diff --git a/modules/operations/move.js b/modules/operations/move.js index e854f64f4..10d003aea 100644 --- a/modules/operations/move.js +++ b/modules/operations/move.js @@ -12,7 +12,6 @@ export function operationMove(selectedIDs, context) { var extent = nodes.reduce(function(extent, node) { return extent.extend(node.extent(context.graph())); }, geoExtent()); - var _disabled; var operation = function() { @@ -27,19 +26,18 @@ export function operationMove(selectedIDs, context) { operation.disabled = function() { - if (_disabled !== undefined) return _disabled; if (extent.area() && extent.percentContainedIn(context.extent()) < 0.8) { - return _disabled = 'too_large'; + return 'too_large'; } else if (someMissing()) { - return _disabled = 'not_downloaded'; + return 'not_downloaded'; } else if (selectedIDs.some(context.hasHiddenConnections)) { - return _disabled = 'connected_to_hidden'; + return 'connected_to_hidden'; } else if (selectedIDs.some(incompleteRelation)) { - return _disabled = 'incomplete_relation'; + return 'incomplete_relation'; } - return _disabled = false; + return false; function someMissing() { diff --git a/modules/operations/orthogonalize.js b/modules/operations/orthogonalize.js index 74594b9e5..41591b378 100644 --- a/modules/operations/orthogonalize.js +++ b/modules/operations/orthogonalize.js @@ -8,7 +8,6 @@ export function operationOrthogonalize(selectedIDs, context) { var _entityID; var _entity; var _geometry; - var _disabled; var action = chooseAction(); if (action) { action.onCompletion = function() { @@ -59,24 +58,23 @@ export function operationOrthogonalize(selectedIDs, context) { }; + // don't cache this because the visible extent could change operation.disabled = function() { if (!action) return ''; - if (_disabled !== undefined) return _disabled; - var extent = _entity.extent(context.graph()); - _disabled = action.disabled(context.graph()); - - if (_disabled) { - return _disabled; - } else if (_geometry !== 'vertex' && extent.percentContainedIn(context.extent()) < 0.8) { - return _disabled = 'too_large'; + var actionDisabled = action.disabled(context.graph()); + if (actionDisabled) { + return actionDisabled; + } else if (_geometry !== 'vertex' && + _entity.extent(context.graph()).percentContainedIn(context.extent()) < 0.8) { + return 'too_large'; } else if (someMissing()) { - return _disabled = 'not_downloaded'; + return 'not_downloaded'; } else if (selectedIDs.some(context.hasHiddenConnections)) { - return _disabled = 'connected_to_hidden'; + return 'connected_to_hidden'; } - return _disabled = false; + return false; function someMissing() { diff --git a/modules/operations/reflect.js b/modules/operations/reflect.js index e6fe52b2d..af5c9c6c8 100644 --- a/modules/operations/reflect.js +++ b/modules/operations/reflect.js @@ -23,7 +23,6 @@ export function operationReflect(selectedIDs, context, axis) { var extent = nodes.reduce(function(extent, node) { return extent.extend(node.extent(context.graph())); }, geoExtent()); - var _disabled; var operation = function() { @@ -38,20 +37,20 @@ export function operationReflect(selectedIDs, context, axis) { }; + // don't cache this because the visible extent could change operation.disabled = function() { - if (_disabled !== undefined) return _disabled; if (extent.area() && extent.percentContainedIn(context.extent()) < 0.8) { - return _disabled = 'too_large'; + return 'too_large'; } else if (someMissing()) { - return _disabled = 'not_downloaded'; + return 'not_downloaded'; } else if (selectedIDs.some(context.hasHiddenConnections)) { - return _disabled = 'connected_to_hidden'; + return 'connected_to_hidden'; } else if (selectedIDs.some(incompleteRelation)) { - return _disabled = 'incomplete_relation'; + return 'incomplete_relation'; } - return _disabled = false; + return false; function someMissing() { diff --git a/modules/operations/rotate.js b/modules/operations/rotate.js index e85dc2592..d81667650 100644 --- a/modules/operations/rotate.js +++ b/modules/operations/rotate.js @@ -12,7 +12,6 @@ export function operationRotate(selectedIDs, context) { var extent = nodes.reduce(function(extent, node) { return extent.extend(node.extent(context.graph())); }, geoExtent()); - var _disabled; var operation = function() { @@ -26,19 +25,18 @@ export function operationRotate(selectedIDs, context) { operation.disabled = function() { - if (_disabled !== undefined) return _disabled; if (extent.area() && extent.percentContainedIn(context.extent()) < 0.8) { - return _disabled = 'too_large'; + return 'too_large'; } else if (someMissing()) { - return _disabled = 'not_downloaded'; + return 'not_downloaded'; } else if (selectedIDs.some(context.hasHiddenConnections)) { - return _disabled = 'connected_to_hidden'; + return 'connected_to_hidden'; } else if (selectedIDs.some(incompleteRelation)) { - return _disabled = 'incomplete_relation'; + return 'incomplete_relation'; } - return _disabled = false; + return false; function someMissing() {