4 ms·
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 chan
by mamon 9y 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?
- VeejayRampay 9y agoBecause 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).
- romanovcode 9y agoThe "redux" way is to make everything immutable to reduce side-effects, implement time-travel debugging and most importantly - make your code very complex.
- joncampbelldev 9y agoImmutability 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.
- romanovcode 9y agoAgree, 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!
- davidmurdoch 9y agoHaha. You just made me choke on my coffee with that last line!