From 8cdfcacdb8cd89acf280c430c52fd96145c0c9d9 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Wed, 23 Dec 2015 10:10:03 -0500 Subject: [PATCH] Cancel debounced history saves in flush() and clearSaved() --- js/id/core/history.js | 1 + js/id/id.js | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/js/id/core/history.js b/js/id/core/history.js index 966e4a567..b256db520 100644 --- a/js/id/core/history.js +++ b/js/id/core/history.js @@ -352,6 +352,7 @@ iD.History = function(context) { }, clearSaved: function() { + context.debouncedSave.cancel(); if (lock.locked()) context.storage(getKey('saved_history'), null); return history; }, diff --git a/js/id/id.js b/js/id/id.js index dbc196727..318f746e9 100644 --- a/js/id/id.js +++ b/js/id/id.js @@ -153,6 +153,7 @@ window.iD = function () { }; context.flush = function() { + context.debouncedSave.cancel(); connection.flush(); features.reset(); history.reset(); @@ -161,11 +162,11 @@ window.iD = function () { // Debounce save, since it's a synchronous localStorage write, // and history changes can happen frequently (e.g. when dragging). - var debouncedSave = _.debounce(context.save, 350); + context.debouncedSave = _.debounce(context.save, 350); function withDebouncedSave(fn) { return function() { var result = fn.apply(history, arguments); - debouncedSave(); + context.debouncedSave(); return result; }; }