diff --git a/client/app/scripts/reducers/__tests__/root-test.js b/client/app/scripts/reducers/__tests__/root-test.js index 86b440b54..f4e80a6c8 100644 --- a/client/app/scripts/reducers/__tests__/root-test.js +++ b/client/app/scripts/reducers/__tests__/root-test.js @@ -500,4 +500,29 @@ describe('RootReducer', () => { nextState = reducer(nextState, {type: ActionTypes.SET_RECEIVED_NODES_DELTA}); expect(nextState.get('gridMode')).toBe(true); }); + it('cleans up old adjacencies', () => { + // Add some nodes + const action1 = { + type: ActionTypes.RECEIVE_NODES_DELTA, + delta: { add: [{ id: 'n1' }, { id: 'n2' }] } + }; + // Show nodes as connected + const action2 = { + type: ActionTypes.RECEIVE_NODES_DELTA, + delta: { + update: [{ id: 'n1', adjacency: ['n2'] }] + } + }; + // Remove the connection + const action3 = { + type: ActionTypes.RECEIVE_NODES_DELTA, + delta: { + update: [{ id: 'n1' }] + } + }; + let nextState = reducer(initialState, action1); + nextState = reducer(nextState, action2); + nextState = reducer(nextState, action3); + expect(nextState.getIn(['nodes', 'n1', 'adjacency'])).toBeFalsy(); + }); }); diff --git a/client/app/scripts/reducers/root.js b/client/app/scripts/reducers/root.js index 3248c2eb6..81d686b8b 100644 --- a/client/app/scripts/reducers/root.js +++ b/client/app/scripts/reducers/root.js @@ -553,7 +553,7 @@ export function rootReducer(state = initialState, action) { // update existing nodes each(action.delta.update, (node) => { if (state.hasIn(['nodes', node.id])) { - state = state.updateIn(['nodes', node.id], n => n.merge(fromJS(node))); + state = state.setIn(['nodes', node.id], fromJS(node)); } });