News for hackers. Stuff that matters.
Re:React Common Tools and Practices: State Management Overview by nawgz on Monday March 08, 2021 @11:06AM (#26387169)
Immer seems like it lets you take the same approach as mobx, but instead of rerendering based on an optimized run-time constructed dependency graph, Immer has to rebuild every single item "under" your mutation. Doesn't this seem like it would be insanely expensive for modifying arrays or things like this?

I also have to imagine the amount of boilerplate you write to use Redux + Immer is orders of magnitude over mobx, but maybe some people prefer it to be slightly more explicit

Re:React Common Tools and Practices: State Management Overview by acemarke on Monday March 08, 2021 @11:39AM (#26387712)
Immutable updates in JS have always required making copies of each level of nesting that has to be updated [0].

However, that process is very tedious and error-prone due to writing lots of nested spread operations.

Immer effectively does those same steps, but automatically. This is all completely different than how Mobx works.

Immer has a slight performance overhead [1], but in practice reducer logic is almost never a meaningful perf bottleneck in a React+Redux app - the cost of updating the UI is might higher.

It's also worth noting that Immer was actually created by Michel Weststrate, the author of Mobx :)

[0] https://redux-toolkit.js.org/usage/immer-reducers#basics-of-...

[1] https://immerjs.github.io/immer/docs/performance

Re:React Common Tools and Practices: State Management Overview by nawgz on Monday March 08, 2021 @11:59AM (#26388068)
Yes, absolutely that is my understanding of immutability. It's why I asked the performance question, but Immer docs are convincing, I see your point.

Not a surprise to me that mwestrate is the author after seeing the description of Immer - he has an excellent graph knowledge and applies clever architectures & optimizations from that.

I recognize it's completely different from how MobX works, I simply mean to say that I feel MobX is superior and this mere idea of mutability / copying instead of smartly updating a graph and correspondingly only the observer portions of your UI seems like the core of that