From 901cab57da42944fd82bee15401467903d4bf470 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Tue, 7 May 2019 10:32:12 -0400 Subject: [PATCH] Remove _disabled caches for operations (re: #6296, reverts 81127d7) see https://github.com/openstreetmap/iD/issues/6296#issuecomment-489259027 (I'll find another way to deal with the menu not matching the tooltip) --- modules/operations/circularize.js | 1 - modules/operations/continue.js | 9 +++------ modules/operations/delete.js | 1 - modules/operations/disconnect.js | 24 ++++++++---------------- modules/operations/downgrade.js | 7 ++----- modules/operations/extract.js | 15 ++++++--------- modules/operations/split.js | 13 +++++-------- modules/operations/straighten.js | 15 ++++++--------- 8 files changed, 30 insertions(+), 55 deletions(-) diff --git a/modules/operations/circularize.js b/modules/operations/circularize.js index aeeb86ac6..3e7aafbfc 100644 --- a/modules/operations/circularize.js +++ b/modules/operations/circularize.js @@ -31,7 +31,6 @@ export function operationCircularize(selectedIDs, context) { // don't cache this because the visible extent could change operation.disabled = function() { - var actionDisabled = action.disabled(context.graph()); if (actionDisabled) { return actionDisabled; diff --git a/modules/operations/continue.js b/modules/operations/continue.js index 732fa47ea..b3a5c17f3 100644 --- a/modules/operations/continue.js +++ b/modules/operations/continue.js @@ -12,7 +12,6 @@ export function operationContinue(selectedIDs, context) { utilArrayGroupBy(entities, function(entity) { return entity.geometry(graph); }) ); var vertex = geometries.vertex[0]; - var _disabled; function candidateWays() { @@ -41,16 +40,14 @@ export function operationContinue(selectedIDs, context) { operation.disabled = function() { - if (_disabled !== undefined) return _disabled; - var candidates = candidateWays(); if (candidates.length === 0) { - return _disabled = 'not_eligible'; + return 'not_eligible'; } else if (candidates.length > 1) { - return _disabled = 'multiple'; + return 'multiple'; } - return _disabled = false; + return false; }; diff --git a/modules/operations/delete.js b/modules/operations/delete.js index 6d513b020..979914a57 100644 --- a/modules/operations/delete.js +++ b/modules/operations/delete.js @@ -72,7 +72,6 @@ export function operationDelete(selectedIDs, context) { operation.disabled = function() { - if (extent.area() && extent.percentContainedIn(context.extent()) < 0.8) { return 'too_large'; } else if (someMissing()) { diff --git a/modules/operations/disconnect.js b/modules/operations/disconnect.js index cafc66841..d47012128 100644 --- a/modules/operations/disconnect.js +++ b/modules/operations/disconnect.js @@ -5,7 +5,6 @@ import { utilGetAllNodes } from '../util/index'; export function operationDisconnect(selectedIDs, context) { - var _disabled; var vertexIDs = []; var wayIDs = []; var otherIDs = []; @@ -78,28 +77,21 @@ export function operationDisconnect(selectedIDs, context) { operation.disabled = function() { - if (_disabled !== undefined) return _disabled; - + var reason; for (var actionIndex in actions) { - var action = actions[actionIndex]; - var actionReason = action.disabled(context.graph()); - if (actionReason) { - _disabled = actionReason; - break; - } + reason = actions[actionIndex].disabled(context.graph()); + if (reason) return reason; } - if (_disabled) { - return _disabled; - } else if (disconnectingWayID && extent.percentContainedIn(context.extent()) < 0.8) { - return _disabled = 'too_large.single'; + if (disconnectingWayID && extent.percentContainedIn(context.extent()) < 0.8) { + return 'too_large.single'; } else if (disconnectingWayID && 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/downgrade.js b/modules/operations/downgrade.js index 3d05ed98e..a8fb6fa5a 100644 --- a/modules/operations/downgrade.js +++ b/modules/operations/downgrade.js @@ -8,7 +8,6 @@ import { uiCmd } from '../ui/cmd'; export function operationDowngrade(selectedIDs, context) { var affectedFeatureCount = 0; var downgradeType; - var _disabled; setDowngradeTypeForEntityIDs(); @@ -96,12 +95,10 @@ export function operationDowngrade(selectedIDs, context) { operation.disabled = function () { - if (_disabled !== undefined) return _disabled; - if (selectedIDs.some(hasWikidataTag)) { - return _disabled = 'has_wikidata_tag'; + return 'has_wikidata_tag'; } - return _disabled = false; + return false; function hasWikidataTag(id) { var entity = context.entity(id); diff --git a/modules/operations/extract.js b/modules/operations/extract.js index d1018ce09..2e494e0b6 100644 --- a/modules/operations/extract.js +++ b/modules/operations/extract.js @@ -8,7 +8,6 @@ import { t } from '../util/locale'; export function operationExtract(selectedIDs, context) { var entityID = selectedIDs.length && selectedIDs[0]; var action = actionExtract(entityID, context.projection); - var _disabled; var geometry = entityID && context.geometry(entityID); var extent = geometry === 'area' && context.entity(entityID).extent(context.graph()); @@ -62,18 +61,16 @@ export function operationExtract(selectedIDs, context) { operation.disabled = function () { - if (_disabled !== undefined) return _disabled; - - _disabled = action.disabled(context.graph()); - if (_disabled) { - return _disabled; + var reason = action.disabled(context.graph()); + if (reason) { + return reason; } else if (geometry === 'vertex' && selectedIDs.some(context.hasHiddenConnections)) { - return _disabled = 'connected_to_hidden'; + return 'connected_to_hidden'; } else if (extent && extent.area() && extent.percentContainedIn(context.extent()) < 0.8) { - return _disabled = 'too_large'; + return 'too_large'; } - return _disabled = false; + return false; }; diff --git a/modules/operations/split.js b/modules/operations/split.js index 1ffd2c3db..94eb7ea67 100644 --- a/modules/operations/split.js +++ b/modules/operations/split.js @@ -10,7 +10,6 @@ export function operationSplit(selectedIDs, context) { var entityID = vertices[0]; var action = actionSplit(entityID); var ways = []; - var _disabled; if (vertices.length === 1) { if (entityID && selectedIDs.length > 1) { @@ -33,16 +32,14 @@ export function operationSplit(selectedIDs, context) { operation.disabled = function() { - if (_disabled !== undefined) return _disabled; - - _disabled = action.disabled(context.graph()); - if (_disabled) { - return _disabled; + var reason = action.disabled(context.graph()); + if (reason) { + return reason; } else if (selectedIDs.some(context.hasHiddenConnections)) { - return _disabled = 'connected_to_hidden'; + return 'connected_to_hidden'; } - return _disabled = false; + return false; }; diff --git a/modules/operations/straighten.js b/modules/operations/straighten.js index 82b3b3808..a2751ecd5 100644 --- a/modules/operations/straighten.js +++ b/modules/operations/straighten.js @@ -13,7 +13,6 @@ export function operationStraighten(selectedIDs, context) { var coords = nodes.map(function(n) { return n.loc; }); var action = chooseAction(); var geometry; - var _disabled; function chooseAction() { @@ -86,18 +85,16 @@ export function operationStraighten(selectedIDs, context) { operation.disabled = function() { - if (_disabled !== undefined) return _disabled; - - _disabled = action.disabled(context.graph()); - if (_disabled) { - return _disabled; + var reason = action.disabled(context.graph()); + if (reason) { + return reason; } 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() {