MobX State Tree is a simple and powerful solution to manage your application state in the Front End, based on MobX. You probably heard about it and maybe you tested it out with an “hello world” project, but... are you using it in production? Reactive Architecture, Model Composition, Mutability and Immutability are just a small subset of all the features that I’m going to walk you through. Join me to find out why MobX State Tree could be your next best friend!
5. MobX» State Management Library
» Helps decoupling View from Business Logic
» Reactive Programming
» Flexible / Unopinionated
6. MobX Observables&reactions
import { observable, autorun} from 'mobx';
const album = observable({
title: 'Californication',
playCount: 0,
});
autorun(() => console.log(`New play count: ${album.playCount}`))
// New play count: 0
album.playCount = 1; // New play count: 1
album.playCount = 24; // New play count: 24
8. MobX RecapObservable state
Mutable Application State
Computed Values
Automatically derived values, lazily evaluated
Reactions
Side effects like autorun or updating a React
component
14. MobX StateTree Stores
Model
» Mutable observable state
» Runtime type information
» Could contain other trees
Views
MobX computed values
Actions
The only way to update the
model
15. MobX StateTree Stores
DeepDive» Mutable and Immutable (Snapshots, Time Travelling)
» Composition
» Lifecycle Methods
» Dependency Injection
37. Takeaways
» Use MobX to learn Reactive Programming
» MobX State Tree provides a structure
» Shape your tree & setup the communication
» Embrace Composition, embrace Reactivity!