SlideShare a Scribd company logo
1 of 26
Download to read offline
MOBX	STATE	TREE
OPINIONATED	STATE
MANAGEMENT
DBS	Launch	Day	2018-01-30
joost@de-vries․name
codestar.nl
joost-de-vries
@jouke




UI	&	STATE	MANAGEMENT
WISHLIST
Keep	state	separate	from	UI	components
Keep	track	of	what	needs	to	be	updated	when
something	changes
Have	well	defined	unidirectional	data	flow
Easy	to	understand
Better	performance
Easy	to	test
Observables!?
Basically	the	benefits	of	Redux
MOBX
A	state	dependency	graph	
using	reactive	programming
Observables	
but	not	implemented	using	RxJs
class AppState {
@observable timer = 0;
constructor() {
setInterval(() => {
this.timer += 1;
}, 1000);
}
@action
reset() {
this.timer = 0;
}
}
Annotate	attributes	that	should	be	tracked	
with	observable	,	computed	or	action
const TimerView = observer(({ appState }) => (
<button onclick="{appState.reset}">
Seconds passed: {appState.timer}
</button>
));
Use	observer	on	components	that	render	data
render(
<div>
<timerview appstate="{new" appstate()}="">
<devtools>
</devtools></timerview></div>,
document.getElementById("root")
);
Render	like	any	React	app
live	code	example
MOBX	CONCEPTS	&
PRINCIPLES
State	drives	the	application
Derived	directly	from	state	are:
The	UI	itself
Derived	data	like	'todos	left'
Backend	integrations	like	sending	changes	to	the
server
mobx	todo
MOBX
Easy	to	understand
Mutable	state
No	time	traveling	debugger
Hard	to	make	'middleware'	for
Lacks	the	immutable	objects	+	pure	functions
approach	of	Redux
“	Vies	maar	lekker”
MOBX	STATE	TREE
Interact	with	an	OO	tree	of	1.	data,	2.	derived	data	3.
actions	and	4.	views
The	tree	is	typed	at	compile	time	and	at	runtime
Changes	are	only	through	actions
..and	automatically	create	immutable	snapshots
..and	json	patches
“Opinionated,	transactional,	MobX
powered	state	container	combining	the
best	features	of	the	immutable	and
mutable	world	for	an	optimal	DX”
const Todo = types
.model("Todo", {
id: types.optional(types.number, () => Math.random()),
title: types.string,
finished: false
})
.actions(self => ({
toggle() {
self.finished = !self.finished
}
}))
export const TodoView = observer(({ todo }) => (
<li>
<input type="checkbox" checked="{todo.finished}" onclick="{todo.toggle}">
{todo.title}
</li>
))
const TodoStore = types
.model("TodoStore", {
todos: types.array(Todo)
})
.views(self => ({
get unfinishedTodoCount() {
return self.todos.filter(todo => !todo.finished).length
}
}))
.actions(self => ({
addTodo(title) {
self.todos.push({ title })
},
handleChange(e) {
self.newTodoTitle = e.target.value
},
handleNewTodoClick(e) {
self.addTodo(self.newTodoTitle)
self.newTodoTitle = ""
}
}))
Code	example
Todo	with	time	travel
Static	typing	with	Typescript
THERE'S	MORE:
Unit	testing
Integration	with	Redux	devtools
Dealing	with	datamodels	that	refer	to	eachother
Async	action	using	js	generators
Integration	with	RxJs
Not	bad	for	a	framework	from
Rotterdam
TO	SUMMARIZE
Seems	to	combine	the	good	parts	of	an	OO
discoverability	&	immutability
Opinionated	so	suitable	for	bigger	projects
Cohesion:	adding	a	feature	doesn't	involve	changes
in	lots	of	places
Typescript	support	is	somewhat	clunky
Mobx	ST	is	a	good	alternative	to	Redux
FURTHER
INFORMATION
M	Weststrate	-	
Fiddle	around	with	
The	websites	of	Mobx	and	Mobx	State	Tree	provide
a	lot	of	information
Becoming	fully	reactive:	how	mobx
works
live	code	examples

More Related Content

Similar to Mobx State Tree - Opinionated State Management

Thinking metrics on React apps
Thinking metrics on React appsThinking metrics on React apps
Thinking metrics on React appsJean Carlo Emer
 
Prescribing RX Responsibly
Prescribing RX ResponsiblyPrescribing RX Responsibly
Prescribing RX ResponsiblyNareg Khoshafian
 
Functional UIs with Java 8 and Vaadin JavaOne2014
Functional UIs with Java 8 and Vaadin JavaOne2014Functional UIs with Java 8 and Vaadin JavaOne2014
Functional UIs with Java 8 and Vaadin JavaOne2014hezamu
 
Redux State Management System A Comprehensive Review
Redux State Management System A Comprehensive ReviewRedux State Management System A Comprehensive Review
Redux State Management System A Comprehensive Reviewijtsrd
 
Displaying additional image types in XMetaL
Displaying additional image types in XMetaLDisplaying additional image types in XMetaL
Displaying additional image types in XMetaLXMetaL
 
redux and angular - up and running
redux and angular - up and runningredux and angular - up and running
redux and angular - up and runningNir Kaufman
 
Utilizing LabVIEW for Varied Control Strategies in Data Acquisition Systems
Utilizing LabVIEW for Varied Control Strategies in Data Acquisition SystemsUtilizing LabVIEW for Varied Control Strategies in Data Acquisition Systems
Utilizing LabVIEW for Varied Control Strategies in Data Acquisition SystemsIRJET Journal
 
Utilizing LabVIEW for Varied Control Strategies in Data Acquisition Systems
Utilizing LabVIEW for Varied Control Strategies in Data Acquisition SystemsUtilizing LabVIEW for Varied Control Strategies in Data Acquisition Systems
Utilizing LabVIEW for Varied Control Strategies in Data Acquisition SystemsIRJET Journal
 
J2ME Lwuit, Storage & Connections (Ft Prasanjit Dey)
J2ME Lwuit, Storage & Connections (Ft   Prasanjit Dey)J2ME Lwuit, Storage & Connections (Ft   Prasanjit Dey)
J2ME Lwuit, Storage & Connections (Ft Prasanjit Dey)Fafadia Tech
 
Android apps development
Android apps developmentAndroid apps development
Android apps developmentMonir Zzaman
 
React state managmenet with Redux
React state managmenet with ReduxReact state managmenet with Redux
React state managmenet with ReduxVedran Blaženka
 
JS Experience 2017 - Reactive Interfaces com React & RxJS
JS Experience 2017 - Reactive Interfaces com React & RxJSJS Experience 2017 - Reactive Interfaces com React & RxJS
JS Experience 2017 - Reactive Interfaces com React & RxJSiMasters
 
RIA implementation patterns
RIA implementation patternsRIA implementation patterns
RIA implementation patternsÜrgo Ringo
 

Similar to Mobx State Tree - Opinionated State Management (20)

BackboneJS + ReactJS
BackboneJS + ReactJSBackboneJS + ReactJS
BackboneJS + ReactJS
 
react redux.pdf
react redux.pdfreact redux.pdf
react redux.pdf
 
Thinking metrics on React apps
Thinking metrics on React appsThinking metrics on React apps
Thinking metrics on React apps
 
react.pdf
react.pdfreact.pdf
react.pdf
 
Prescribing RX Responsibly
Prescribing RX ResponsiblyPrescribing RX Responsibly
Prescribing RX Responsibly
 
MobX for dummies
MobX for dummiesMobX for dummies
MobX for dummies
 
Functional UIs with Java 8 and Vaadin JavaOne2014
Functional UIs with Java 8 and Vaadin JavaOne2014Functional UIs with Java 8 and Vaadin JavaOne2014
Functional UIs with Java 8 and Vaadin JavaOne2014
 
Redux State Management System A Comprehensive Review
Redux State Management System A Comprehensive ReviewRedux State Management System A Comprehensive Review
Redux State Management System A Comprehensive Review
 
Displaying additional image types in XMetaL
Displaying additional image types in XMetaLDisplaying additional image types in XMetaL
Displaying additional image types in XMetaL
 
redux and angular - up and running
redux and angular - up and runningredux and angular - up and running
redux and angular - up and running
 
Utilizing LabVIEW for Varied Control Strategies in Data Acquisition Systems
Utilizing LabVIEW for Varied Control Strategies in Data Acquisition SystemsUtilizing LabVIEW for Varied Control Strategies in Data Acquisition Systems
Utilizing LabVIEW for Varied Control Strategies in Data Acquisition Systems
 
Utilizing LabVIEW for Varied Control Strategies in Data Acquisition Systems
Utilizing LabVIEW for Varied Control Strategies in Data Acquisition SystemsUtilizing LabVIEW for Varied Control Strategies in Data Acquisition Systems
Utilizing LabVIEW for Varied Control Strategies in Data Acquisition Systems
 
Let's Redux!
Let's Redux!Let's Redux!
Let's Redux!
 
J2ME Lwuit, Storage & Connections (Ft Prasanjit Dey)
J2ME Lwuit, Storage & Connections (Ft   Prasanjit Dey)J2ME Lwuit, Storage & Connections (Ft   Prasanjit Dey)
J2ME Lwuit, Storage & Connections (Ft Prasanjit Dey)
 
Android apps development
Android apps developmentAndroid apps development
Android apps development
 
React
ReactReact
React
 
React state managmenet with Redux
React state managmenet with ReduxReact state managmenet with Redux
React state managmenet with Redux
 
React vs Angular2
React vs Angular2React vs Angular2
React vs Angular2
 
JS Experience 2017 - Reactive Interfaces com React & RxJS
JS Experience 2017 - Reactive Interfaces com React & RxJSJS Experience 2017 - Reactive Interfaces com React & RxJS
JS Experience 2017 - Reactive Interfaces com React & RxJS
 
RIA implementation patterns
RIA implementation patternsRIA implementation patterns
RIA implementation patterns
 

Recently uploaded

VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Christo Ananth
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptMsecMca
 

Recently uploaded (20)

VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 

Mobx State Tree - Opinionated State Management