From 19560ebc90ccfc1ebae60ba5d94afd9bd4ccc008 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Thu, 12 Jul 2018 15:39:04 -0400 Subject: [PATCH] Properly save and restore caches when entering/leaving the walkthrough --- modules/services/osm.js | 37 ++++++++++++++++++++++--------------- modules/ui/intro/intro.js | 4 ++-- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/modules/services/osm.js b/modules/services/osm.js index 7ef04526d..583980f18 100644 --- a/modules/services/osm.js +++ b/modules/services/osm.js @@ -1,4 +1,5 @@ import _chunk from 'lodash-es/chunk'; +import _cloneDeep from 'lodash-es/cloneDeep'; import _extend from 'lodash-es/extend'; import _forEach from 'lodash-es/forEach'; import _filter from 'lodash-es/filter'; @@ -893,9 +894,27 @@ export default { }, - loadedTiles: function(_) { - if (!arguments.length) return _tileCache.loaded; - _tileCache.loaded = _; + caches: function(obj) { + if (!arguments.length) { + return { + tile: _cloneDeep(_tileCache), + note: _cloneDeep(_noteCache), + user: _cloneDeep(_userCache) + }; + } + + if (obj.tile) { + _tileCache = obj.tile; + _tileCache.inflight = {}; + } + if (obj.note) { + _noteCache = obj.note; + _tileCache.inflight = {}; + } + if (obj.user) { + _userCache = obj.user; + } + return this; }, @@ -969,18 +988,6 @@ export default { }, - loadedNotes: function(_) { - if (!arguments.length) return _noteCache.loaded; - _noteCache.loaded = _; - return this; - }, - - - notesCache: function() { - return _noteCache; - }, - - toggleNoteStatus: function(note, comment, callback) { if (!(note instanceof osmNote) && !(this.getNote(note.id))) return; if (!this.authenticated()) return; diff --git a/modules/ui/intro/intro.js b/modules/ui/intro/intro.js index 9243c4547..3dcf67537 100644 --- a/modules/ui/intro/intro.js +++ b/modules/ui/intro/intro.js @@ -71,7 +71,7 @@ export function uiIntro(context) { var background = context.background().baseLayerSource(); var overlays = context.background().overlayLayerSources(); var opacity = d3_selectAll('#map .layer-background').style('opacity'); - var loadedTiles = osm && osm.loadedTiles(); + var caches = osm && osm.caches(); var baseEntities = context.history().graph().base().entities; var countryCode = services.geocoder.countryCode; @@ -147,7 +147,7 @@ export function uiIntro(context) { curtain.remove(); navwrap.remove(); d3_selectAll('#map .layer-background').style('opacity', opacity); - if (osm) { osm.toggle(true).reset().loadedTiles(loadedTiles); } + if (osm) { osm.toggle(true).reset().caches(caches); } context.history().reset().merge(_values(baseEntities)); context.background().baseLayerSource(background); overlays.forEach(function (d) { context.background().toggleOverlayLayer(d); });