mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-14 17:52:55 +00:00
Adjust the timing of localStorage saves
If localStorage writes were free, we'd want to just save on every history change. Second best is to debounce the write. Writing on mode change is problematic; it sometimes happens when not desired and sometimes doesn't happen when desired. Fixes #1857.
This commit is contained in:
22
js/id/id.js
22
js/id/id.js
@@ -76,11 +76,6 @@ window.iD = function () {
|
||||
|
||||
/* History */
|
||||
context.graph = history.graph;
|
||||
context.perform = history.perform;
|
||||
context.replace = history.replace;
|
||||
context.pop = history.pop;
|
||||
context.undo = history.undo;
|
||||
context.redo = history.redo;
|
||||
context.changes = history.changes;
|
||||
context.intersects = history.intersects;
|
||||
|
||||
@@ -104,6 +99,23 @@ window.iD = function () {
|
||||
return context;
|
||||
};
|
||||
|
||||
// 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);
|
||||
function withDebouncedSave(fn) {
|
||||
return function() {
|
||||
var result = fn.apply(history, arguments);
|
||||
debouncedSave();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
context.perform = withDebouncedSave(history.perform);
|
||||
context.replace = withDebouncedSave(history.replace);
|
||||
context.pop = withDebouncedSave(history.pop);
|
||||
context.undo = withDebouncedSave(history.undo);
|
||||
context.redo = withDebouncedSave(history.redo);
|
||||
|
||||
/* Graph */
|
||||
context.hasEntity = function(id) {
|
||||
return history.graph().hasEntity(id);
|
||||
|
||||
@@ -15,8 +15,6 @@ iD.modes.Browse = function(context) {
|
||||
iD.modes.DragNode(context).behavior];
|
||||
|
||||
mode.enter = function() {
|
||||
context.save();
|
||||
|
||||
behaviors.forEach(function(behavior) {
|
||||
context.install(behavior);
|
||||
});
|
||||
|
||||
@@ -70,8 +70,6 @@ iD.modes.Select = function(context, selectedIDs) {
|
||||
};
|
||||
|
||||
mode.enter = function() {
|
||||
context.save();
|
||||
|
||||
behaviors.forEach(function(behavior) {
|
||||
context.install(behavior);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user