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)
This commit is contained in:
Bryan Housel
2019-05-07 10:32:12 -04:00
parent d3a53309b7
commit 901cab57da
8 changed files with 30 additions and 55 deletions
-1
View File
@@ -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;
+3 -6
View File
@@ -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;
};
-1
View File
@@ -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()) {
+8 -16
View File
@@ -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() {
+2 -5
View File
@@ -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);
+6 -9
View File
@@ -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;
};
+5 -8
View File
@@ -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;
};
+6 -9
View File
@@ -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() {