Simplify, fix spec

This commit is contained in:
John Firebaugh
2013-02-27 16:01:51 -08:00
parent 957121d92e
commit b751c1ece9
2 changed files with 11 additions and 13 deletions

View File

@@ -1,5 +1,11 @@
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/DeleteWayAction.as
iD.actions.DeleteWay = function(wayId) {
function deleteNode(node, graph) {
return !graph.parentWays(node).length &&
!graph.parentRelations(node).length &&
!node.hasInterestingTags();
}
return function(graph) {
var way = graph.entity(wayId);
@@ -8,20 +14,12 @@ iD.actions.DeleteWay = function(wayId) {
graph = graph.replace(parent.removeMember(wayId));
});
way.nodes.forEach(function(nodeId) {
var node = graph.entity(nodeId);
// Circular ways include nodes more than once, so they
// can be deleted on earlier iterations of this loop.
if (!node) return;
_.uniq(way.nodes).forEach(function(nodeId) {
graph = graph.replace(way.removeNode(nodeId));
if (!graph.parentWays(node).length &&
!graph.parentRelations(node).length) {
if (!node.hasInterestingTags()) {
graph = graph.remove(node);
}
var node = graph.entity(nodeId);
if (deleteNode(node, graph)) {
graph = graph.remove(node);
}
});

View File

@@ -47,7 +47,7 @@ describe("iD.actions.DeleteWay", function() {
c = iD.Node(),
way = iD.Way({nodes: [a.id, b.id, c.id, a.id]}),
action = iD.actions.DeleteWay(way.id),
graph = iD.Graph([a, b, way]).update(action);
graph = iD.Graph([a, b, c, way]).update(action);
expect(graph.entity(a.id)).to.be.undefined;
expect(graph.entity(b.id)).to.be.undefined;
expect(graph.entity(c.id)).to.be.undefined;