From 077e5cc9ce80240ad8a9cae8f09717cd82f0ac32 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 5 Dec 2012 16:42:48 -0500 Subject: [PATCH] Rename various actions --- NOTES.md | 2 +- index.html | 6 +++--- js/id/actions/add_node.js | 2 +- js/id/actions/add_way_node.js | 2 +- js/id/actions/change_entity_tags.js | 7 +++++++ js/id/actions/change_tags.js | 7 ------- js/id/actions/delete_node.js | 4 ++-- js/id/actions/delete_way.js | 4 ++-- js/id/actions/move.js | 2 +- js/id/actions/noop.js | 2 +- ...ion_entity.js => remove_relation_member.js} | 4 ++-- js/id/actions/remove_way_node.js | 2 +- ...{change_way_direction.js => reverse_way.js} | 2 +- js/id/actions/start_way.js | 2 +- js/id/modes/add_area.js | 4 ++-- js/id/modes/add_place.js | 2 +- js/id/modes/add_road.js | 6 +++--- js/id/modes/draw_area.js | 12 ++++++------ js/id/modes/draw_road.js | 18 +++++++++--------- js/id/modes/select.js | 8 ++++---- js/id/renderer/map.js | 6 +++--- test/index.html | 6 +++--- test/spec/actions/add_way_node.js | 6 +++--- test/spec/actions/remove_way_node.js | 4 ++-- test/spec/graph/history.js | 2 +- 25 files changed, 61 insertions(+), 61 deletions(-) create mode 100644 js/id/actions/change_entity_tags.js delete mode 100644 js/id/actions/change_tags.js rename js/id/actions/{remove_relation_entity.js => remove_relation_member.js} (51%) rename js/id/actions/{change_way_direction.js => reverse_way.js} (85%) diff --git a/NOTES.md b/NOTES.md index bb14002a0..7c24ac2ff 100644 --- a/NOTES.md +++ b/NOTES.md @@ -89,7 +89,7 @@ reverting to the previous version. The persistent data structure approach also takes advantage of the fact that the typical change modifies only a small portion of the graph. The unchanged majority of the graph is shared between revisions, -keeping memory use to a minimum. For example, the `iD.actions.removeWayNode` action removes a single +keeping memory use to a minimum. For example, the `iD.actions.RemoveWayNode` action removes a single node from a way. It produces new versions of three objects: * The Array of nodes in the way. diff --git a/index.html b/index.html index a674a2e7c..75f8e1123 100644 --- a/index.html +++ b/index.html @@ -43,14 +43,14 @@ - - + - + + diff --git a/js/id/actions/add_node.js b/js/id/actions/add_node.js index 291811409..f8916e50b 100644 --- a/js/id/actions/add_node.js +++ b/js/id/actions/add_node.js @@ -1,5 +1,5 @@ // https://github.com/openstreetmap/josm/blob/mirror/src/org/openstreetmap/josm/command/AddCommand.java -iD.actions.addNode = function(node) { +iD.actions.AddNode = function(node) { return function(graph) { return graph.replace(node, 'added a place'); }; diff --git a/js/id/actions/add_way_node.js b/js/id/actions/add_way_node.js index bc4b7f347..7c8772dba 100644 --- a/js/id/actions/add_way_node.js +++ b/js/id/actions/add_way_node.js @@ -1,5 +1,5 @@ // https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/AddNodeToWayAction.as -iD.actions.addWayNode = function(way, node, index) { +iD.actions.AddWayNode = function(way, node, index) { return function(graph) { var nodes = way.nodes.slice(); nodes.splice(index || nodes.length, 0, node.id); diff --git a/js/id/actions/change_entity_tags.js b/js/id/actions/change_entity_tags.js new file mode 100644 index 000000000..97c67f0aa --- /dev/null +++ b/js/id/actions/change_entity_tags.js @@ -0,0 +1,7 @@ +iD.actions.ChangeEntityTags = function(entity, tags) { + return function(graph) { + return graph.replace(entity.update({ + tags: tags + }), 'changed tags'); + }; +}; diff --git a/js/id/actions/change_tags.js b/js/id/actions/change_tags.js deleted file mode 100644 index 81b99760e..000000000 --- a/js/id/actions/change_tags.js +++ /dev/null @@ -1,7 +0,0 @@ -iD.actions.changeTags = function(node, tags) { - return function(graph) { - return graph.replace(node.update({ - tags: tags - }), 'changed tags'); - }; -}; diff --git a/js/id/actions/delete_node.js b/js/id/actions/delete_node.js index 1d3737a86..c7813ce48 100644 --- a/js/id/actions/delete_node.js +++ b/js/id/actions/delete_node.js @@ -3,12 +3,12 @@ iD.actions.DeleteNode = function(node) { return function(graph) { graph.parentWays(node.id) .forEach(function(parent) { - graph = iD.actions.removeWayNode(parent, node)(graph); + graph = iD.actions.RemoveWayNode(parent, node)(graph); }); graph.parentRelations(node.id) .forEach(function(parent) { - graph = iD.actions.removeRelationEntity(parent, node)(graph); + graph = iD.actions.RemoveRelationMember(parent, node)(graph); }); return graph.remove(node, 'removed a node'); diff --git a/js/id/actions/delete_way.js b/js/id/actions/delete_way.js index ae5fe27a8..641f61af2 100644 --- a/js/id/actions/delete_way.js +++ b/js/id/actions/delete_way.js @@ -3,13 +3,13 @@ iD.actions.DeleteWay = function(way) { return function(graph) { graph.parentRelations(way.id) .forEach(function(parent) { - graph = iD.actions.removeRelationEntity(parent, way)(graph); + graph = iD.actions.RemoveRelationMember(parent, way)(graph); }); way.nodes.forEach(function (id) { var node = graph.entity(id); - graph = iD.actions.removeWayNode(way, node)(graph); + graph = iD.actions.RemoveWayNode(way, node)(graph); if (!graph.parentWays(id).length && !graph.parentRelations(id).length) { if (!node.hasInterestingTags()) { diff --git a/js/id/actions/move.js b/js/id/actions/move.js index d67af763f..6c15e8bdc 100644 --- a/js/id/actions/move.js +++ b/js/id/actions/move.js @@ -1,6 +1,6 @@ // https://github.com/openstreetmap/josm/blob/mirror/src/org/openstreetmap/josm/command/MoveCommand.java // https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/MoveNodeAction.as -iD.actions.move = function(entity, loc) { +iD.actions.Move = function(entity, loc) { return function(graph) { return graph.replace(entity.update({loc: loc}), 'moved an element'); }; diff --git a/js/id/actions/noop.js b/js/id/actions/noop.js index ddae5dde5..b729fe0c0 100644 --- a/js/id/actions/noop.js +++ b/js/id/actions/noop.js @@ -1,4 +1,4 @@ -iD.actions.noop = function() { +iD.actions.Noop = function() { return function(graph) { return graph; }; diff --git a/js/id/actions/remove_relation_entity.js b/js/id/actions/remove_relation_member.js similarity index 51% rename from js/id/actions/remove_relation_entity.js rename to js/id/actions/remove_relation_member.js index 4a9fd1c70..b10224c26 100644 --- a/js/id/actions/remove_relation_entity.js +++ b/js/id/actions/remove_relation_member.js @@ -1,6 +1,6 @@ -iD.actions.removeRelationEntity = function(relation, entity) { +iD.actions.RemoveRelationMember = function(relation, member) { return function(graph) { - var members = _.without(relation.members, entity.id); + var members = _.without(relation.members, member.id); return graph.replace(relation.update({members: members}), 'removed from a relation'); }; }; diff --git a/js/id/actions/remove_way_node.js b/js/id/actions/remove_way_node.js index 16f9883bb..bf645b6b2 100644 --- a/js/id/actions/remove_way_node.js +++ b/js/id/actions/remove_way_node.js @@ -1,4 +1,4 @@ -iD.actions.removeWayNode = function(way, node) { +iD.actions.RemoveWayNode = function(way, node) { return function(graph) { var nodes = _.without(way.nodes, node.id); return graph.replace(way.update({nodes: nodes}), 'removed from a road'); diff --git a/js/id/actions/change_way_direction.js b/js/id/actions/reverse_way.js similarity index 85% rename from js/id/actions/change_way_direction.js rename to js/id/actions/reverse_way.js index cfa637336..4d14eb8f1 100644 --- a/js/id/actions/change_way_direction.js +++ b/js/id/actions/reverse_way.js @@ -1,5 +1,5 @@ // https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/AddNodeToWayAction.as -iD.actions.changeWayDirection = function(way) { +iD.actions.ReverseWay = function(way) { return function(graph) { return graph.replace(way.update({ nodes: way.nodes.slice() diff --git a/js/id/actions/start_way.js b/js/id/actions/start_way.js index 8e7ea7631..6c82e389d 100644 --- a/js/id/actions/start_way.js +++ b/js/id/actions/start_way.js @@ -1,4 +1,4 @@ -iD.actions.startWay = function(way) { +iD.actions.StartWay = function(way) { return function(graph) { return graph.replace(way, 'started a road'); }; diff --git a/js/id/modes/add_area.js b/js/id/modes/add_area.js index 1f4832738..976e4c584 100644 --- a/js/id/modes/add_area.js +++ b/js/id/modes/add_area.js @@ -21,8 +21,8 @@ iD.modes.AddArea = function() { node = iD.Node({loc: mode.map.mouseCoordinates()}); } - mode.history.perform(iD.actions.startWay(way)); - mode.history.perform(iD.actions.addWayNode(way, node)); + mode.history.perform(iD.actions.StartWay(way)); + mode.history.perform(iD.actions.AddWayNode(way, node)); mode.controller.enter(iD.modes.DrawArea(way.id)); }); diff --git a/js/id/modes/add_place.js b/js/id/modes/add_place.js index 633d88aea..780023e76 100644 --- a/js/id/modes/add_place.js +++ b/js/id/modes/add_place.js @@ -10,7 +10,7 @@ iD.modes.AddPlace = function() { mode.map.surface.on('click.addplace', function() { var node = iD.Node({loc: mode.map.mouseCoordinates(), _poi: true}); - mode.history.perform(iD.actions.addNode(node)); + mode.history.perform(iD.actions.AddNode(node)); mode.controller.enter(iD.modes.Select(node)); }); diff --git a/js/id/modes/add_road.js b/js/id/modes/add_road.js index b2a89cc62..da7420071 100644 --- a/js/id/modes/add_road.js +++ b/js/id/modes/add_road.js @@ -39,15 +39,15 @@ iD.modes.AddRoad = function() { var index = iD.util.geo.chooseIndex(datum, d3.mouse(mode.map.surface.node()), mode.map); var connectedWay = mode.history.graph().entity(datum.id); - mode.history.perform(iD.actions.addWayNode(connectedWay, node, index)); + mode.history.perform(iD.actions.AddWayNode(connectedWay, node, index)); } else { // begin a new way node = iD.Node({loc: mode.map.mouseCoordinates()}); } if (start) { - mode.history.perform(iD.actions.startWay(way)); - mode.history.perform(iD.actions.addWayNode(way, node)); + mode.history.perform(iD.actions.StartWay(way)); + mode.history.perform(iD.actions.AddWayNode(way, node)); } mode.controller.enter(iD.modes.DrawRoad(way.id, direction)); diff --git a/js/id/modes/draw_area.js b/js/id/modes/draw_area.js index ca1352432..e90b251bc 100644 --- a/js/id/modes/draw_area.js +++ b/js/id/modes/draw_area.js @@ -11,10 +11,10 @@ iD.modes.DrawArea = function(way_id) { firstnode_id = _.first(way.nodes), node = iD.Node({loc: mode.map.mouseCoordinates()}); - mode.history.perform(iD.actions.addWayNode(way, node)); + mode.history.perform(iD.actions.AddWayNode(way, node)); mode.map.surface.on('mousemove.drawarea', function() { - mode.history.replace(iD.actions.addWayNode(way, node.update({loc: mode.map.mouseCoordinates()}))); + mode.history.replace(iD.actions.AddWayNode(way, node.update({loc: mode.map.mouseCoordinates()}))); }); mode.map.surface.on('click.drawarea', function() { @@ -24,20 +24,20 @@ iD.modes.DrawArea = function(way_id) { if (datum.type === 'node') { if (datum.id == firstnode_id) { - mode.history.replace(iD.actions.addWayNode(way, + mode.history.replace(iD.actions.AddWayNode(way, mode.history.graph().entity(way.nodes[0]))); - mode.history.perform(iD.actions.changeTags(way, _.omit(way.tags, 'elastic'))); + mode.history.perform(iD.actions.ChangeEntityTags(way, _.omit(way.tags, 'elastic'))); // End by clicking on own tail return mode.controller.enter(iD.modes.Select(way)); } else { // connect a way to an existing way - mode.history.replace(iD.actions.addWayNode(way, datum)); + mode.history.replace(iD.actions.AddWayNode(way, datum)); } } else { node = node.update({loc: mode.map.mouseCoordinates()}); - mode.history.replace(iD.actions.addWayNode(way, node)); + mode.history.replace(iD.actions.AddWayNode(way, node)); } mode.controller.enter(iD.modes.DrawArea(way_id)); diff --git a/js/id/modes/draw_road.js b/js/id/modes/draw_road.js index 6b31ada42..3317367d0 100644 --- a/js/id/modes/draw_road.js +++ b/js/id/modes/draw_road.js @@ -14,10 +14,10 @@ iD.modes.DrawRoad = function(way_id, direction) { firstNode = way.nodes[0], lastNode = _.last(way.nodes); - mode.history.perform(iD.actions.addWayNode(way, node, index)); + mode.history.perform(iD.actions.AddWayNode(way, node, index)); mode.map.surface.on('mousemove.drawroad', function() { - mode.history.replace(iD.actions.addWayNode(way, node.update({loc: mode.map.mouseCoordinates()}), index)); + mode.history.replace(iD.actions.AddWayNode(way, node.update({loc: mode.map.mouseCoordinates()}), index)); }); mode.map.surface.on('click.drawroad', function() { @@ -30,31 +30,31 @@ iD.modes.DrawRoad = function(way_id, direction) { // If mode is drawing a loop and mode is not the drawing // end of the stick, finish the circle if (direction === 'forward' && datum.id == firstNode) { - mode.history.replace(iD.actions.addWayNode(way, + mode.history.replace(iD.actions.AddWayNode(way, mode.history.graph().entity(firstNode), index)); } else if (direction === 'backward' && datum.id == lastNode) { - mode.history.replace(iD.actions.addWayNode(way, + mode.history.replace(iD.actions.AddWayNode(way, mode.history.graph().entity(lastNode), index)); } - mode.history.perform(iD.actions.changeTags(way, _.omit(way.tags, 'elastic'))); + mode.history.perform(iD.actions.ChangeEntityTags(way, _.omit(way.tags, 'elastic'))); // End by clicking on own tail return mode.controller.enter(iD.modes.Select(way)); } else { // connect a way to an existing way - mode.history.replace(iD.actions.addWayNode(way, datum, index)); + mode.history.replace(iD.actions.AddWayNode(way, datum, index)); } } else if (datum.type === 'way') { node = node.update({loc: mode.map.mouseCoordinates()}); - mode.history.replace(iD.actions.addWayNode(way, node, index)); + mode.history.replace(iD.actions.AddWayNode(way, node, index)); var connectedWay = mode.history.graph().entity(datum.id); var connectedIndex = iD.modes.chooseIndex(datum, d3.mouse(mode.map.surface.node()), mode.map); - mode.history.perform(iD.actions.addWayNode(connectedWay, node, connectedIndex)); + mode.history.perform(iD.actions.AddWayNode(connectedWay, node, connectedIndex)); } else { node = node.update({loc: mode.map.mouseCoordinates()}); - mode.history.replace(iD.actions.addWayNode(way, node, index)); + mode.history.replace(iD.actions.AddWayNode(way, node, index)); } mode.controller.enter(iD.modes.DrawRoad(way_id, direction)); diff --git a/js/id/modes/select.js b/js/id/modes/select.js index 82fbd7204..57a1cf251 100644 --- a/js/id/modes/select.js +++ b/js/id/modes/select.js @@ -16,14 +16,14 @@ iD.modes.Select = function (entity) { if (!dragging) { dragging = iD.util.trueObj([entity.id].concat( _.pluck(mode.history.graph().parentWays(entity.id), 'id'))); - mode.history.perform(iD.actions.noop()); + mode.history.perform(iD.actions.Noop()); } entity.nodes.forEach(function(node) { var start = mode.map.projection(node.loc); var end = mode.map.projection.invert([start[0] + d3.event.dx, start[1] + d3.event.dy]); node.loc = end; - mode.history.replace(iD.actions.move(node, end)); + mode.history.replace(iD.actions.Move(node, end)); }); }) .on('dragend', function () { @@ -53,9 +53,9 @@ iD.modes.Select = function (entity) { .call(inspector); inspector.on('changeTags', function(d, tags) { - mode.history.perform(iD.actions.changeTags(history.graph().entity(d.id), tags)); + mode.history.perform(iD.actions.ChangeEntityTags(history.graph().entity(d.id), tags)); }).on('changeWayDirection', function(d) { - mode.history.perform(iD.actions.changeWayDirection(d)); + mode.history.perform(iD.actions.ReverseWay(d)); }).on('remove', function() { remove(); }).on('close', function() { diff --git a/js/id/renderer/map.js b/js/id/renderer/map.js index 85f9faaae..ca314ec97 100644 --- a/js/id/renderer/map.js +++ b/js/id/renderer/map.js @@ -26,16 +26,16 @@ iD.Map = function() { if (!dragging) { if (entity.accuracy) { var way = history.graph().entity(entity.way); - history.perform(iD.actions.addWayNode(way, iD.Node(entity), entity.index)); + history.perform(iD.actions.AddWayNode(way, iD.Node(entity), entity.index)); } dragging = iD.util.trueObj([entity.id].concat( _.pluck(history.graph().parentWays(entity.id), 'id'))); - history.perform(iD.actions.noop()); + history.perform(iD.actions.Noop()); } var to = projection.invert([d3.event.x, d3.event.y]); - history.replace(iD.actions.move(entity, to)); + history.replace(iD.actions.Move(entity, to)); redraw(); }) diff --git a/test/index.html b/test/index.html index 8381f45fa..5f681b444 100644 --- a/test/index.html +++ b/test/index.html @@ -45,14 +45,14 @@ - - + - + + diff --git a/test/spec/actions/add_way_node.js b/test/spec/actions/add_way_node.js index f3f58944a..e1df86158 100644 --- a/test/spec/actions/add_way_node.js +++ b/test/spec/actions/add_way_node.js @@ -1,15 +1,15 @@ -describe("iD.actions.addWayNode", function () { +describe("iD.actions.AddWayNode", function () { it("adds a node to the end of a way", function () { var way = iD.Way(), node = iD.Node({id: "n1"}), - graph = iD.actions.addWayNode(way, node)(iD.Graph()); + graph = iD.actions.AddWayNode(way, node)(iD.Graph()); expect(graph.entity(way.id).nodes).to.eql(["n1"]); }); it("adds a node to a way at the specified index", function () { var way = iD.Way({nodes: ["n1", "n3"]}), node = iD.Node({id: "n2"}), - graph = iD.actions.addWayNode(way, node, 1)(iD.Graph()); + graph = iD.actions.AddWayNode(way, node, 1)(iD.Graph()); expect(graph.entity(way.id).nodes).to.eql(["n1", "n2", "n3"]); }); }); diff --git a/test/spec/actions/remove_way_node.js b/test/spec/actions/remove_way_node.js index 117dfb3bb..56a302ec0 100644 --- a/test/spec/actions/remove_way_node.js +++ b/test/spec/actions/remove_way_node.js @@ -1,8 +1,8 @@ -describe("iD.actions.removeWayNode", function () { +describe("iD.actions.RemoveWayNode", function () { it("removes a node from a way", function () { var node = iD.Node({id: "n1"}), way = iD.Way({id: "w1", nodes: ["n1"]}), - graph = iD.actions.removeWayNode(way, node)(iD.Graph({n1: node, w1: way})); + graph = iD.actions.RemoveWayNode(way, node)(iD.Graph({n1: node, w1: way})); expect(graph.entity(way.id).nodes).to.eql([]); }); }); diff --git a/test/spec/graph/history.js b/test/spec/graph/history.js index e49543421..dda4f3168 100644 --- a/test/spec/graph/history.js +++ b/test/spec/graph/history.js @@ -33,7 +33,7 @@ describe("History", function () { it("does not emit a change event when performing a noop", function () { history.on('change', spy); - history.perform(iD.actions.noop); + history.perform(iD.actions.Noop); expect(spy).not.to.have.been.called; }); });