keep nodes cache intact while websocket is closed

This commit is contained in:
David Kaltschmidt
2015-06-16 15:15:46 +02:00
parent ad5bfb67ec
commit 35e5335359
2 changed files with 16 additions and 1 deletions
@@ -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({});
});
+8 -1
View File
@@ -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