mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-20 15:34:49 +02:00
History#reset
This commit is contained in:
@@ -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
@@ -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
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user