Changed merge to re-assign in RECEIVE_NODES_DELTA

This commit is contained in:
jpellizzari
2017-02-03 10:51:47 -08:00
parent 43cb7548d8
commit f82ec445f8
2 changed files with 26 additions and 1 deletions

View File

@@ -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();
});
});

View File

@@ -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));
}
});