Hacker News new | ask | show | jobs
by mamon 3230 days ago
Maybe this is stupid question, cause I don't know React or Redux, but why would anyone want the data structures holding page data to be immutable? Data can change any time due to user actions, immutability would only get in the way, wouldn't it?
2 comments

Because if everything is immutable, it gets very easy to compare two given states and know when and what to update, by using referential equality (if you create a new object every time, then a different "ID" means the data has changed, to grossly simplify the idea behind it).
The "redux" way is to make everything immutable to reduce side-effects, implement time-travel debugging and most importantly - make your code very complex.
Immutability in js is awful hence the complexity, a library like immutable.js can make it better, but the language is just not built for it.

Because imperative code and persistent, immutable data do not play nicely together.

Agree, but the problem is that you need unreal discipline because what I see in projects that are 1+ years old half of the code is using Immutable.JS and half is not - and that is even worse!
Haha. You just made me choke on my coffee with that last line!