History#reset

This commit is contained in:
John Firebaugh
2012-12-03 18:09:05 -05:00
parent 8a8d6fae32
commit 0a1e0bdfe4
3 changed files with 28 additions and 9 deletions
+9 -2
View File
@@ -1,6 +1,5 @@
iD.History = function() {
var stack = [iD.Graph()],
index = 0,
var stack, index,
dispatch = d3.dispatch('change');
function maybeChange() {
@@ -89,8 +88,16 @@ iD.History = function() {
create: this.create(),
'delete': this['delete']()
};
},
reset: function () {
stack = [iD.Graph()];
index = 0;
dispatch.change();
}
};
history.reset();
return d3.rebind(history, dispatch, 'on');
};
+1 -1
View File
@@ -79,7 +79,7 @@ var iD = function(container) {
var l = iD.loading('uploading changes to openstreetmap');
connection.putChangeset(history.changes(), e.comment, function() {
l.remove();
map.history(iD.History());
history.reset();
map.flush().redraw();
});
}
+18 -6
View File
@@ -4,7 +4,8 @@ describe("History", function () {
action = function() { return graph; };
beforeEach(function () {
history = iD.History();
history = iD.History();
spy = sinon.spy();
});
describe("#graph", function () {
@@ -39,13 +40,24 @@ describe("History", function () {
});
});
describe("change", function () {
var spy;
beforeEach(function () {
spy = sinon.spy();
describe("#reset", function () {
it("clears the version stack", function () {
history.perform(action);
history.perform(action);
history.undo();
history.reset();
expect(history.undoAnnotation()).to.be.undefined;
expect(history.redoAnnotation()).to.be.undefined;
});
it("emits a change event", function () {
history.on('change', spy);
history.reset();
expect(spy).to.have.been.called;
});
});
describe("change", function () {
it("is not emitted when performing a noop", function () {
history.on('change', spy);
history.perform(iD.actions.noop);