Cancel debounced history saves in flush() and clearSaved()

This commit is contained in:
Bryan Housel
2015-12-23 10:10:03 -05:00
parent a7a8a6f38e
commit 8cdfcacdb8
2 changed files with 4 additions and 2 deletions
+1
View File
@@ -352,6 +352,7 @@ iD.History = function(context) {
},
clearSaved: function() {
context.debouncedSave.cancel();
if (lock.locked()) context.storage(getKey('saved_history'), null);
return history;
},
+3 -2
View File
@@ -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;
};
}