Webcamp Zagreb, 2016
React is a great view layer, but what about the rest of the app structure?
React is a great view layer, but if you want to create something more than a simple TODO app, youll need some other parts. First of, youll need a data structure and a way to handle the changes in it. Although the most simple way to do it could be to take parts of a framework youre used to (e.g. Backbone Collections/Models), there is something better out there. First, there was the Flux architecture, made by Facebook itself - it forced us to change and consume our data in a certain way in order to prevent developers from shooting themselves in the foot. Then there was Redux - a state container that preaches immutability and time travel. While Redux is great, and enables us great things like hot module reloading, it is also very strict and introduces a lot of boilerplate code. MobX, on the other side, has almost no boilerplate code, can be strict when/if you want it to be, and gives you a nice performance boost for free.
https://2016.webcampzg.org/talks/view/making-react-part-of-something-greater/
1 of 63
Download to read offline
More Related Content
Making react part of something greater
1. Making React part of
something greater
DARKO KUKOVEC
JS TEAM LEAD @ INFINUM
@DarkoKukovec
7. REACT - THE WEIRD PARTS
JSX?!?
Different way of thinking
Component state
8. REACT - THE GOOD PARTS
Virtual DOM
Think about the end goal, not about the journey
You render the final state
React takes care of the actual changes
Efficient
11. STATE MANAGEMENT
React - Encapsulated UI Components
Application State & Business logic?
STATE MANAGEMENT
Source: https://medium.freecodecamp.com/is-mvc-dead-for-the-frontend-35b4d1fe39ec
13. DIY STATE MANAGEMENT
How to (efficiently) rerender component on data change?
setState is tricky
14. DIY STATE MANAGEMENT
How to (efficiently) rerender component on data change?
setState is tricky
Standards
Source: https://xkcd.com/927/
15. MRC - MODEL-REACT-CONTROLLER
e.g. Replace Backbone views with components
http://todomvc.com/examples/react-backbone/
Backbone mutable by nature -> Bad for React perf
Legacy codebase?
18. FLUX
Data down, actions up
Source: http://fluxxor.com/what-is-flux.html
19. FLUX
Data down, actions up
Source: http://fluxxor.com/what-is-flux.html
20. FLUX
Store
Business logic + Application state
Only one allowed to change application state
All actions synchronous
Async operations trigger actions on state change
40. REDUX VS. MOBX
Redux
Faster
Less boilerplate
Flexible
MobX
Bigger community
Better Dev Tools
Less magic
Source: https://twitter.com/phillip_webb/status/705909774001377280
52. import {useStrict} from "mobx";
useStrict(true);
// In a random place
function selectTalkAction(talk) {
talk.selected = true;
}
// [mobx] Invariant failed: It is not allowed to create or
change state outside an `action` when MobX is in strict
mode. Wrap the current method in `action` if this state
change is intended
// TalkActions.js
@action function selectTalkAction(talk) {
talk.selected = true;
}
MobX
useStrict