From 728036be51ea227635f052d182dc5bdd4e4f4bb1 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Sat, 20 Jun 2015 12:21:29 -0400 Subject: [PATCH] Don't write unsavable changes to localStorage (closes #2705) --- js/id/core/history.js | 2 +- test/spec/core/history.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/js/id/core/history.js b/js/id/core/history.js index 90cb947af..966e4a567 100644 --- a/js/id/core/history.js +++ b/js/id/core/history.js @@ -198,7 +198,7 @@ iD.History = function(context) { }, toJSON: function() { - if (stack.length <= 1) return; + if (!this.hasChanges()) return; var allEntities = {}, baseEntities = {}, diff --git a/test/spec/core/history.js b/test/spec/core/history.js index d8be41a63..4bcd1d477 100644 --- a/test/spec/core/history.js +++ b/test/spec/core/history.js @@ -272,6 +272,13 @@ describe("iD.History", function () { }); describe("#toJSON", function() { + it("doesn't generate unsaveable changes", function() { + var node_1 = iD.Node({id: 'n-1'}); + history.perform(iD.actions.AddEntity(node_1)); + history.perform(iD.actions.DeleteNode('n-1')); + expect(history.toJSON()).to.be.not.ok; + }); + it("generates v3 JSON", function() { var node_1 = iD.Node({id: 'n-1'}), node1 = iD.Node({id: 'n1'}),