Michel Weststrate, Mendix, Rotterdam — State Management is Easy

Michel Weststrate, Mendix, Rotterdam — State Management is Easy

Michel Weststrate, Mendix, Rotterdam — State Management is Easy

State is the heart of each application and there is no quicker way to create buggy, unmanageable applications then by producing inconsistent state. Hence many state management solutions try to restrict the ways in which you can modify state, for example by making state immutable. But this introduces new problems; data needs to be normalized, referential integrity can no longer be guaranteed and it becomes next to impossible to use powerful concepts like prototypes.

At Mendix these restrictions where unacceptable and so MobX was born. MobX makes state management simple again by addressing the root issue: it makes it impossible to produce an inconsistent state. This makes state management simple and scalable again.

5799a3c0434b91ef7e00e730629390f0?s=128

React Amsterdam

April 21, 2016
Tweet

Transcript

  1. State Management Is Easy Michel Weststrate @mweststrate Mendix React Amsterdam

    2016 1
  2. The DOM Was Hard... 2

  3. State Management Is Hard 3

  4. Redux: Simple & Elegant Concept 4

  5. Pulls Amazing Tricks 5

  6. New Things To Learn! Reducers Immutables Denormalization Connect Selectors Smart

    & Dumb components Thunks & Sagas 6
  7. MobX - No Pedaling 7

  8. 8

  9. 9

  10. MobX 1. The Idea 2. Simple 3. Fast 4. Scalable

    5. Questions 10
  11. Why Is State Management Hard? Σ State Aggregates Lookup tables

    Server Storage UI 11 affects:
  12. 1. State Should Be Minimally Defined No Caching No Data

    Duplication No Cascading State Changes 12
  13. 2. Everything Should Be Derived Automatically Define derivations MobX ensures

    efficiency & consistency 13
  14. Actions State Views Modify Updates Σ 14

  15. Simple github.com/mweststrate/mobx-contacts-list/ 15

  16. 16

  17. @observable / @computed 17

  18. observer 18

  19. observer 19

  20. @observer 20

  21. Actions 21

  22. @observable enables MobX to observe your data @observer MobX ensures

    that this component is consistent with the state @computed MobX ensures that this value is consistent with the state 22
  23. Fast Numbers! 23

  24. 24

  25. Such Fast Only track data which is accessed in last

    render Minimizes amount of computations PureRenderMixin 25
  26. Scalable MobX @ Mendix 26

  27. ~500 classes apidocs.mendix.com/modelsdk/ 27

  28. 28

  29. Demo link 29

  30. 30

  31. Scalable 31 Minimal state Graphs: natural mental model Simple code

    Architectural freedom Third party friendly actions? State views? Modify Updates
  32. State Management Is Simple! Questions? #reactamsterdam @mweststrate "I am putting

    my eggs into React and MobX basket. So far building two huge React apps I haven't had any reason to regret it." "It's almost ridiculous how simple and powerful MobX + React is" "Working with #mobx is basically a continuous loop of me going “this is way too simple, it definitely won’t work” only to be proven wrong" "Try react-mobx with es6 and you will love it so much that you will hug someone." "MobX compared to Redux feels like gravity gun compared to a wheelbarrow" "I used to be Angular guy, but seeing how observables play well with React, I would never go back to it." "I have built big app with MobX already and comparing to the one before that which was using Redux, it is simpler to read and much easier to reason about." "Cuts out much boilerplate and complexity." "The #mobx is the way I always want things to be! It's really surprising simple and fast! Totally awesome! Don't miss it!" 32