From 0a1e0bdfe4af0953398f9777b480d7142e944cb3 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 3 Dec 2012 18:09:05 -0500 Subject: [PATCH] History#reset --- js/id/graph/history.js | 11 +++++++++-- js/id/id.js | 2 +- test/spec/history.js | 24 ++++++++++++++++++------ 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/js/id/graph/history.js b/js/id/graph/history.js index 41feba27c..11a6111ce 100644 --- a/js/id/graph/history.js +++ b/js/id/graph/history.js @@ -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'); }; diff --git a/js/id/id.js b/js/id/id.js index c053504c4..6a54170b8 100644 --- a/js/id/id.js +++ b/js/id/id.js @@ -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(); }); } diff --git a/test/spec/history.js b/test/spec/history.js index 821e15390..f45265b93 100644 --- a/test/spec/history.js +++ b/test/spec/history.js @@ -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);