From d83ec7f1eb4862b58b62022da76d9d809c3996ac Mon Sep 17 00:00:00 2001 From: Brandon Liu Date: Sat, 19 Jan 2013 22:29:11 -0800 Subject: [PATCH] Create method history.hasChanges --- js/id/graph/history.js | 6 ++++++ test/spec/graph/history.js | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/js/id/graph/history.js b/js/id/graph/history.js index e31fa5ef9..bf7cdfc88 100644 --- a/js/id/graph/history.js +++ b/js/id/graph/history.js @@ -109,6 +109,12 @@ iD.History = function() { }; }, + hasChanges: function() { + return !!d3.sum(d3.values(this.changes()).map(function(c) { + return c.length; + }));; + }, + imagery_used: function(source) { if (source) imagery_used = source; else return _.without( diff --git a/test/spec/graph/history.js b/test/spec/graph/history.js index 15fe10964..c3fa536f1 100644 --- a/test/spec/graph/history.js +++ b/test/spec/graph/history.js @@ -126,6 +126,18 @@ describe("iD.History", function () { }); }); + describe("#hasChanges", function() { + it("is true when any of change's values are nonempty", function() { + var node = iD.Node(); + history.perform(function (graph) { return graph.replace(node); }); + expect(history.hasChanges()).to.eql(true); + }); + + it("is false when any of change's values are empty", function() { + expect(history.hasChanges()).to.eql(false); + }); + }); + describe("#reset", function () { it("clears the version stack", function () { history.perform(action, "annotation");