In redux I understand that state is immutable and when you create new state you are essentially updating the object with what ever new information there is and then totally rewriting the state.
Today I had a thought and I am not sure how stupid it is.
Is it computationally expensive to keep re-writing the state? I know that this is one of the major paradigms of Redux, but I want to know if this makes sense from a memory and space perspective.
You are allowed to mutate the state in Redux but you should not do it at any cost because you'd be coding in Redux anti-patterns
Now back to Redux, functions in reducers should be pure functions. here is why:
Redux algorithm checks if a state has been updated by comparing the memory location of the previous and the next state.
On the other side, if instead of mutating the object you create a new one, when redux compares the memory location of previousState (the state before you changed it) and the nextState(the new one which you sent), Redux at this point realises that there has been a change and it updates the store with you latest state.
Redux anti-patterns: https://github.com/coodoo/react-redux-isomorphic-example/issues/9
impure functions and issues with Redux devtools:
Why Redux need reducers to be "pure functions"
Redux devtools: https://github.com/gaearon/redux-devtools