mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
Rename various actions
This commit is contained in:
2
NOTES.md
2
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.
|
||||
|
||||
@@ -43,14 +43,14 @@
|
||||
<script src='js/id/actions.js'></script>
|
||||
<script src='js/id/actions/add_node.js'></script>
|
||||
<script src='js/id/actions/add_way_node.js'></script>
|
||||
<script src='js/id/actions/change_tags.js'></script>
|
||||
<script src='js/id/actions/change_way_direction.js'></script>
|
||||
<script src='js/id/actions/change_entity_tags.js'></script>
|
||||
<script src="js/id/actions/delete_node.js"></script>
|
||||
<script src="js/id/actions/delete_way.js"></script>
|
||||
<script src='js/id/actions/move.js'></script>
|
||||
<script src='js/id/actions/noop.js'></script>
|
||||
<script src='js/id/actions/remove_relation_entity.js'></script>
|
||||
<script src='js/id/actions/remove_relation_member.js'></script>
|
||||
<script src='js/id/actions/remove_way_node.js'></script>
|
||||
<script src='js/id/actions/reverse_way.js'></script>
|
||||
<script src='js/id/actions/start_way.js'></script>
|
||||
|
||||
<script src='js/id/modes.js'></script>
|
||||
|
||||
@@ -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');
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
7
js/id/actions/change_entity_tags.js
Normal file
7
js/id/actions/change_entity_tags.js
Normal file
@@ -0,0 +1,7 @@
|
||||
iD.actions.ChangeEntityTags = function(entity, tags) {
|
||||
return function(graph) {
|
||||
return graph.replace(entity.update({
|
||||
tags: tags
|
||||
}), 'changed tags');
|
||||
};
|
||||
};
|
||||
@@ -1,7 +0,0 @@
|
||||
iD.actions.changeTags = function(node, tags) {
|
||||
return function(graph) {
|
||||
return graph.replace(node.update({
|
||||
tags: tags
|
||||
}), 'changed tags');
|
||||
};
|
||||
};
|
||||
@@ -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');
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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');
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
iD.actions.noop = function() {
|
||||
iD.actions.Noop = function() {
|
||||
return function(graph) {
|
||||
return graph;
|
||||
};
|
||||
|
||||
@@ -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');
|
||||
};
|
||||
};
|
||||
@@ -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');
|
||||
|
||||
@@ -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()
|
||||
@@ -1,4 +1,4 @@
|
||||
iD.actions.startWay = function(way) {
|
||||
iD.actions.StartWay = function(way) {
|
||||
return function(graph) {
|
||||
return graph.replace(way, 'started a road');
|
||||
};
|
||||
|
||||
@@ -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));
|
||||
});
|
||||
|
||||
@@ -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));
|
||||
});
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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();
|
||||
})
|
||||
|
||||
@@ -45,14 +45,14 @@
|
||||
<script src='../js/id/actions.js'></script>
|
||||
<script src='../js/id/actions/add_node.js'></script>
|
||||
<script src='../js/id/actions/add_way_node.js'></script>
|
||||
<script src='../js/id/actions/change_tags.js'></script>
|
||||
<script src='../js/id/actions/change_way_direction.js'></script>
|
||||
<script src='../js/id/actions/change_entity_tags.js'></script>
|
||||
<script src="../js/id/actions/delete_node.js"></script>
|
||||
<script src="../js/id/actions/delete_way.js"></script>
|
||||
<script src='../js/id/actions/move.js'></script>
|
||||
<script src='../js/id/actions/noop.js'></script>
|
||||
<script src='../js/id/actions/remove_relation_entity.js'></script>
|
||||
<script src='../js/id/actions/remove_relation_member.js'></script>
|
||||
<script src='../js/id/actions/remove_way_node.js'></script>
|
||||
<script src='../js/id/actions/reverse_way.js'></script>
|
||||
<script src='../js/id/actions/start_way.js'></script>
|
||||
|
||||
<script src='../js/id/modes.js'></script>
|
||||
|
||||
@@ -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"]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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([]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user