Features
MobX is one of the least obtrusive libraries you can use for state management. That makes the MobX
approach not just simple, but very scalable as well.
Using Classes and Real References
With MobX, you don't need to normalize your data. This makes the library very suitable for very complex domain models.
Referential Integrity is Guaranteed
Since data doesn't need to be normalized, and MobX automatically tracks the relations between state and derivations, you get referential integrity for free. Rendering something that is accessed through three levels of indirection?
No problem, MobX will track them and re-render whenever one of the references changes. As a result, staleness bugs are a thing of the past. As a programmer, you might forget that changing some data might influence a seemingly unrelated component in a corner case. MobX won't forget.
Simpler Actions are Easier to Maintain
As demonstrated above, modifying state when using MobX is very straightforward. You simply write down your intentions. MobX will take care of the rest.
Fine-Grained Observability is Efficient
MobX builds a graph of all the derivations in your application to find the least number of re-computations that is needed to prevent staleness. "Derive everything" might sound expensive, MobX builds a virtual derivation graph to minimize the number of recomputations needed to keep derivations in sync with the state.
In fact, when testing MobX at Mendix we found out that using this library to track the relations in our code is often a lot more efficient then pushing changes through our application by using handwritten events or "smart" selector based container components.
The simple reason is that MobX will establish far more fine grained 'listeners' on your data then you would do as a programmer.
Secondly, MobX sees the causality between derivations so it can order them in such a way that no derivation has to run twice or introduces a glitch.
Easy Interoperability
MobX works with plain JavaScript structures. Due to its unobtrusiveness, it work with most JavaScript libraries out of the box, without needing MobX specific library flavors.
So you can simply keep using your existing router, data fetching, and utility libraries like react-router
, director
, superagent
, lodash
, etc.
For the same reason, you can use it our of the box both server and client side, in isomorphic applications and with react-native
.
The result of this is that you often need to learn less new concepts when using MobX in comparison to other state management solutions.