Skip to content

Instantly share code, notes, and snippets.

@davidnorth
Created August 26, 2015 16:29
Show Gist options
  • Save davidnorth/b6c5991756a7fdaf4d81 to your computer and use it in GitHub Desktop.
Save davidnorth/b6c5991756a7fdaf4d81 to your computer and use it in GitHub Desktop.
Enabling redux dev tools causes identity of parts of Immutable state to change when it shouldn't, breaking pure render.
let Immutable = require('immutable'),
devTools = require('redux-devtools').devTools;
let { createStore, applyMiddleware, compose } = require('redux');
let state = Immutable.fromJS({
one: { number: 1 }
});
function reducer(state, action) {
if(action.type === 'ONE') {
return state.setIn(['one', 'number'], 11);
} else {
return state;
}
}
let store = compose(
devTools(), // Comment this out and the spec passes
createStore
)(reducer, state);
describe("identity of state.get('one')", () => {
it("doesn't change when an action is dispatched that doesn't update it", () => {
// This issue occurs only when the part of the state in question has previously been updated
store.dispatch({type: 'ONE'});
// Store a reference to the updated part of the state
let lastOne = store.getState().get('one');
// Then call action that updates other parts of the state, or does nothing at all
store.dispatch({type: 'ANYTHING'});
// Now compare identity
// This fails, they have the same attributes but not the same identity
expect(lastOne === store.getState().get('one')).toBeTruthy();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment