mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-21 15:56:56 +02:00
Wrap all actions in Graph#update
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
iD.actions.MoveWay = function(wayId, delta, projection) {
|
||||
return function(graph) {
|
||||
return graph.update(function (graph) {
|
||||
var way = graph.entity(wayId);
|
||||
var way = graph.entity(wayId);
|
||||
|
||||
_.uniq(way.nodes).forEach(function (id) {
|
||||
var node = graph.entity(id),
|
||||
start = projection(node.loc),
|
||||
end = projection.invert([start[0] + delta[0], start[1] + delta[1]]);
|
||||
graph = graph.replace(node.move(end));
|
||||
});
|
||||
_.uniq(way.nodes).forEach(function(id) {
|
||||
var node = graph.entity(id),
|
||||
start = projection(node.loc),
|
||||
end = projection.invert([start[0] + delta[0], start[1] + delta[1]]);
|
||||
graph = graph.replace(node.move(end));
|
||||
});
|
||||
|
||||
return graph;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -12,10 +12,11 @@ iD.History = function() {
|
||||
annotation = actions.pop();
|
||||
}
|
||||
|
||||
var graph = stack[index].graph;
|
||||
for (var i = 0; i < actions.length; i++) {
|
||||
graph = actions[i](graph);
|
||||
}
|
||||
var graph = stack[index].graph.update(function (graph) {
|
||||
for (var i = 0; i < actions.length; i++) {
|
||||
graph = actions[i](graph);
|
||||
}
|
||||
});
|
||||
|
||||
return {graph: graph, annotation: annotation, imagery_used: imagery_used};
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@ describe("iD.History", function () {
|
||||
|
||||
describe("#perform", function () {
|
||||
it("updates the graph", function () {
|
||||
var graph = iD.Graph();
|
||||
history.perform(d3.functor(graph));
|
||||
expect(history.graph()).to.equal(graph);
|
||||
var node = iD.Node();
|
||||
history.perform(function (graph) { return graph.replace(node); });
|
||||
expect(history.graph().entity(node.id)).to.equal(node);
|
||||
});
|
||||
|
||||
it("pushes an undo annotation", function () {
|
||||
@@ -43,9 +43,9 @@ describe("iD.History", function () {
|
||||
|
||||
describe("#replace", function () {
|
||||
it("updates the graph", function () {
|
||||
var graph = iD.Graph();
|
||||
history.replace(d3.functor(graph));
|
||||
expect(history.graph()).to.equal(graph);
|
||||
var node = iD.Node();
|
||||
history.replace(function (graph) { return graph.replace(node); });
|
||||
expect(history.graph().entity(node.id)).to.equal(node);
|
||||
});
|
||||
|
||||
it("replaces the undo annotation", function () {
|
||||
|
||||
Reference in New Issue
Block a user