From 35e53353592e8c3de4b10c4e7fc8aa15c853ab85 Mon Sep 17 00:00:00 2001 From: David Kaltschmidt Date: Tue, 16 Jun 2015 15:15:46 +0200 Subject: [PATCH] keep nodes cache intact while websocket is closed --- client/app/scripts/stores/__tests__/app-store-test.js | 8 ++++++++ client/app/scripts/stores/app-store.js | 9 ++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/client/app/scripts/stores/__tests__/app-store-test.js b/client/app/scripts/stores/__tests__/app-store-test.js index c3487ea2c..7fe4a514a 100644 --- a/client/app/scripts/stores/__tests__/app-store-test.js +++ b/client/app/scripts/stores/__tests__/app-store-test.js @@ -39,6 +39,11 @@ describe('AppStore', function() { type: ActionTypes.HIT_ESC_KEY }; + const ReceiveEmptyNodesDeltaAction = { + type: ActionTypes.RECEIVE_NODES_DELTA, + delta: {} + }; + const ReceiveNodesDeltaAction = { type: ActionTypes.RECEIVE_NODES_DELTA, delta: { @@ -146,6 +151,9 @@ describe('AppStore', function() { expect(AppStore.getNodes()).toEqual(NODE_SET); registeredCallback(CloseWebsocketAction); + expect(AppStore.getNodes()).toEqual(NODE_SET); + + registeredCallback(ReceiveEmptyNodesDeltaAction); expect(AppStore.getNodes()).toEqual({}); }); diff --git a/client/app/scripts/stores/app-store.js b/client/app/scripts/stores/app-store.js index 16f558d55..4309bf489 100644 --- a/client/app/scripts/stores/app-store.js +++ b/client/app/scripts/stores/app-store.js @@ -39,6 +39,7 @@ let nodes = {}; let nodeDetails = null; let selectedNodeId = null; let topologies = []; +let websocketClosed = true; // Store API @@ -162,7 +163,7 @@ AppStore.registeredCallback = function(payload) { break; case ActionTypes.CLOSE_WEBSOCKET: - nodes = {}; + websocketClosed = true; AppStore.emit(AppStore.CHANGE_EVENT); break; @@ -211,6 +212,12 @@ AppStore.registeredCallback = function(payload) { errorUrl = null; + // flush nodes cache after re-connect + if (websocketClosed) { + nodes = {}; + } + websocketClosed = false; + // nodes that no longer exist _.each(payload.delta.remove, function(nodeId) { // in case node disappears before mouseleave event