SlideShare a Scribd company logo
1 of 22
Download to read offline
MOBX FOR DUMMIES
YAUHENI NIKANOVICH
MobX is a simple, scalable and battle
tested state management solution
The philosophy behind MobX is very
simple: Anything that can be derived
from the application state, should be
derived. Automatically.
REACT-MOBX
React and MobX together are a powerful combination.
‣ React renders the application state by providing mechanisms
to translate it into a tree of renderable components.
‣ MobX provides the mechanism to store and update the
application state that React then uses.
MobX adds observable capabilities to existing data structures like
objects, arrays and class instances.
Observable
ES2016 (ES7) ES5
Usage:
‣ observable(value)
‣ @observable classProperty = value
Observer
Observer function / decorator can be used to turn ReactJS
components into reactive components.
It wraps the component's render function in mobx.autorun to
make sure that any data that is used during the rendering of a
component forces a re-rendering upon change.
Observer is available through the separate mobx-react package.
Usage:
‣ observer(value)
‣ @observer class className { . . . }
Observer
STATELESSCOMPONENT STATEFULL COMPONENT
Observer and store(s)
In order to bind a component and store(s) we can use Provider
component.
Provider allows to inject passed stores from the child components
by using props.
Observer adds lifecycle hook
When using mobx-react you can define a new life cycle hook,
componentWillReact that will be triggered when a component
will be scheduled to re-render because data it observes has
changed
‣ componentWillReact doesn't take arguments
‣ componentWillReact won't fire before the initial render

(use componentWillMount instead)
When to apply Observer
There is a simple rule: all components that render observable data
With @observer there is no need to distinguish 'smart'
components from 'dumb' components for the purpose of
rendering
It makes sure that whenever you start using observable data,
wrapped component will respond it
MobX-React DevTools
In combination with @observer you can use the MobX-React
DevTools, it shows exactly when your components are re-rendered,
also it shows data dependencies of your components
MobX-React DevTools
VISUALIZE COMPONENT RE-RENDER
SHOW COMPONENT DEPENDENCY TREE
LOG STATE CHANGES/REACTION
Characteristics of Observer component
‣ Observer only subscribe to the data structures that were actively
used during the last render. This means that you cannot under-
subscribe or over-subscribe. You can even use data in your rendering
that will only be available at later moment in time. This is ideal for
asynchronously loading data.
‣ You are not required to declare what data a component will use.
Instead, dependencies are determined at runtime and tracked in a
very fine-grained manner.
‣ Usually reactive components have no or little state, as it is often more
convenient to encapsulate (view) state in objects that are shared with
other component. But you are still free to use native state.
‣ @observer implements shouldComponentUpdate in the same way as
PureRenderMixin so that children are not re-rendered unnecessary.
‣ Reactive components sideways load data. Parent components won't
re-render unnecessarily even when child components will.
‣ @observer does not depend on React's context system.
Action
Any application has actions. Actions are anything that modify
the state. With MobX you can make it explicit in your code
where your actions live by marking them. Actions help you to
structure your code better.
Action is advised to use on any function that modifies
Observables or has side effects.
Action also provides useful debugging information in
combination with DevTools
Action using action is mandatory when strict mode is enabled
Action takes a function as argument and returns it after
wrapping it with transaction and allowStateChanges
Action
Usage:
‣ action(fn)
‣ action(name, fn)
‣ @action classMethod()
‣ @action(name) classMethod()
Transaction is a kind of scope of operations. Observer will not
notified before transaction will not done
Note that transaction runs completely synchronously
Transactions can be nested. Only after completing the outer
transaction pending reactions will be run
Transaction
allowStateChanges
Can be used to (dis)allow state changes in a certain function.
Used internally by action to allow changes, and by computed
and observer to disallow state changes.
Strict mode
Enables / disables strict mode globally.
In strict mode, it is not allowed to change any state outside of
an action
Usage:
‣ useStrict(boolean)
Violation consequence:
Computed
With MobX you can define values that will be derived
automatically when relevant data is modified. By using the
@computed decorator
PropTypes
mobx-react provides the following additional PropTypes which can
be used to validate against MobX structures:
‣ observableArray
‣ observableArrayOf(React.PropTypes.number)
‣ observableMap
‣ observableObject
‣ arrayOrObservableArray
‣ arrayOrObservableArrayOf(React.PropTypes.number)
‣ objectOrObservableObject
Import PropTypes from mobx-react and use it:
‣ PropTypes.observableArray
PROS AND CONS
Pros:
‣ Makes your components reactive
‣ Easy to understand
‣ Friendly for users with

OOP background
‣ Less code
‣ Steep learning curve
‣ Responsive community
‣ ?? Magic ??
Cons:
?? Magic ??
Useful Links:
‣ Git repo: https://github.com/mobxjs/mobx
‣ Official Documentation: https://mobx.js.org/index.html
‣ MobX Creator on Medium: https://medium.com/@mweststrate
‣ Cheatsheet: http://ricostacruz.com/cheatsheets/mobx.html
‣ Boilerplates: https://mobx.js.org/faq/boilerplates.html
Q & A
YAUHENI NIKANOVICH
Thanks for attention
SLIDES: goo.gl/5qSjIt

EMAIL: zhenyanikon@gmail.com
2017

More Related Content

What's hot

React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux IntroductionNikolaus Graf
 
Introduction to react
Introduction to reactIntroduction to react
Introduction to reactkiranabburi
 
React js programming concept
React js programming conceptReact js programming concept
React js programming conceptTariqul islam
 
Jumping-with-java8
Jumping-with-java8Jumping-with-java8
Jumping-with-java8Dhaval Dalal
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJSKnoldus Inc.
 
Node.js File system & Streams
Node.js File system & StreamsNode.js File system & Streams
Node.js File system & StreamsEyal Vardi
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Previewvaluebound
 
不同尺寸與解析度的螢幕下,Android 程式 UI 的設計與解決方式
不同尺寸與解析度的螢幕下,Android 程式 UI 的設計與解決方式不同尺寸與解析度的螢幕下,Android 程式 UI 的設計與解決方式
不同尺寸與解析度的螢幕下,Android 程式 UI 的設計與解決方式信宏 陳
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners Varun Raj
 
Learning React - I
Learning React - ILearning React - I
Learning React - IMitch Chen
 
React JS - A quick introduction tutorial
React JS - A quick introduction tutorialReact JS - A quick introduction tutorial
React JS - A quick introduction tutorialMohammed Fazuluddin
 

What's hot (20)

React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
 
An Introduction to Redux
An Introduction to ReduxAn Introduction to Redux
An Introduction to Redux
 
Introduction to react
Introduction to reactIntroduction to react
Introduction to react
 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
 
Jumping-with-java8
Jumping-with-java8Jumping-with-java8
Jumping-with-java8
 
ReactJS
ReactJSReactJS
ReactJS
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJS
 
Node.js File system & Streams
Node.js File system & StreamsNode.js File system & Streams
Node.js File system & Streams
 
React js
React jsReact js
React js
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
 
Ngrx: Redux in angular
Ngrx: Redux in angularNgrx: Redux in angular
Ngrx: Redux in angular
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
 
Second Level Cache in JPA Explained
Second Level Cache in JPA ExplainedSecond Level Cache in JPA Explained
Second Level Cache in JPA Explained
 
session.ppt
session.pptsession.ppt
session.ppt
 
不同尺寸與解析度的螢幕下,Android 程式 UI 的設計與解決方式
不同尺寸與解析度的螢幕下,Android 程式 UI 的設計與解決方式不同尺寸與解析度的螢幕下,Android 程式 UI 的設計與解決方式
不同尺寸與解析度的螢幕下,Android 程式 UI 的設計與解決方式
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners
 
Redux workshop
Redux workshopRedux workshop
Redux workshop
 
Learning React - I
Learning React - ILearning React - I
Learning React - I
 
React js
React jsReact js
React js
 
React JS - A quick introduction tutorial
React JS - A quick introduction tutorialReact JS - A quick introduction tutorial
React JS - A quick introduction tutorial
 

Similar to MobX for dummies

Mobx for Dummies - Yauheni Nikanowich - React Warsaw #5
Mobx for Dummies - Yauheni Nikanowich - React Warsaw #5Mobx for Dummies - Yauheni Nikanowich - React Warsaw #5
Mobx for Dummies - Yauheni Nikanowich - React Warsaw #5Marcin Mieszek
 
downloads_introduction to redux.pptx
downloads_introduction to redux.pptxdownloads_introduction to redux.pptx
downloads_introduction to redux.pptxNavneetKumar111924
 
Understanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree TechnologiesUnderstanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree TechnologiesWalking Tree Technologies
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
Understanding react hooks
Understanding react hooksUnderstanding react hooks
Understanding react hooksSamundra khatri
 
React and MobX: A Truly Reactive App
React and MobX:  A Truly Reactive AppReact and MobX:  A Truly Reactive App
React and MobX: A Truly Reactive AppJacob Orshalick
 
an Introduction to Redux
an Introduction to Reduxan Introduction to Redux
an Introduction to ReduxAmin Ashtiani
 
Sagas Middleware Architecture
Sagas Middleware ArchitectureSagas Middleware Architecture
Sagas Middleware ArchitectureMateusz Bosek
 
Presentation on "An Introduction to ReactJS"
Presentation on "An Introduction to ReactJS"Presentation on "An Introduction to ReactJS"
Presentation on "An Introduction to ReactJS"Flipkart
 
Getting started with react & redux
Getting started with react & reduxGetting started with react & redux
Getting started with react & reduxGirish Talekar
 
FRONTEND BOOTCAMP 4.pptx
FRONTEND BOOTCAMP 4.pptxFRONTEND BOOTCAMP 4.pptx
FRONTEND BOOTCAMP 4.pptxEhtesham46
 
Introduction to Redux (for Angular and React devs)
Introduction to Redux (for Angular and React devs)Introduction to Redux (for Angular and React devs)
Introduction to Redux (for Angular and React devs)Fabio Biondi
 
Corso su ReactJS
Corso su ReactJSCorso su ReactJS
Corso su ReactJSLinkMe Srl
 
Meetup - Getting Started with MVVM Light for WPF - 11 may 2019
Meetup  - Getting Started with MVVM Light for WPF - 11 may 2019Meetup  - Getting Started with MVVM Light for WPF - 11 may 2019
Meetup - Getting Started with MVVM Light for WPF - 11 may 2019iFour Technolab Pvt. Ltd.
 
Advanced Redux architecture - WHAT/WHEN/WHY/HOW
Advanced Redux architecture - WHAT/WHEN/WHY/HOWAdvanced Redux architecture - WHAT/WHEN/WHY/HOW
Advanced Redux architecture - WHAT/WHEN/WHY/HOWMateusz Bosek
 
React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥Remo Jansen
 

Similar to MobX for dummies (20)

Mobx for Dummies - Yauheni Nikanowich - React Warsaw #5
Mobx for Dummies - Yauheni Nikanowich - React Warsaw #5Mobx for Dummies - Yauheni Nikanowich - React Warsaw #5
Mobx for Dummies - Yauheni Nikanowich - React Warsaw #5
 
Mob x in react
Mob x in reactMob x in react
Mob x in react
 
Redux
ReduxRedux
Redux
 
React-JS.pptx
React-JS.pptxReact-JS.pptx
React-JS.pptx
 
downloads_introduction to redux.pptx
downloads_introduction to redux.pptxdownloads_introduction to redux.pptx
downloads_introduction to redux.pptx
 
Understanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree TechnologiesUnderstanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree Technologies
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
Understanding react hooks
Understanding react hooksUnderstanding react hooks
Understanding react hooks
 
React and MobX: A Truly Reactive App
React and MobX:  A Truly Reactive AppReact and MobX:  A Truly Reactive App
React and MobX: A Truly Reactive App
 
an Introduction to Redux
an Introduction to Reduxan Introduction to Redux
an Introduction to Redux
 
Sagas Middleware Architecture
Sagas Middleware ArchitectureSagas Middleware Architecture
Sagas Middleware Architecture
 
Presentation on "An Introduction to ReactJS"
Presentation on "An Introduction to ReactJS"Presentation on "An Introduction to ReactJS"
Presentation on "An Introduction to ReactJS"
 
Getting started with react & redux
Getting started with react & reduxGetting started with react & redux
Getting started with react & redux
 
FRONTEND BOOTCAMP 4.pptx
FRONTEND BOOTCAMP 4.pptxFRONTEND BOOTCAMP 4.pptx
FRONTEND BOOTCAMP 4.pptx
 
Introduction to Redux (for Angular and React devs)
Introduction to Redux (for Angular and React devs)Introduction to Redux (for Angular and React devs)
Introduction to Redux (for Angular and React devs)
 
Corso su ReactJS
Corso su ReactJSCorso su ReactJS
Corso su ReactJS
 
Meetup - Getting Started with MVVM Light for WPF - 11 may 2019
Meetup  - Getting Started with MVVM Light for WPF - 11 may 2019Meetup  - Getting Started with MVVM Light for WPF - 11 may 2019
Meetup - Getting Started with MVVM Light for WPF - 11 may 2019
 
React
ReactReact
React
 
Advanced Redux architecture - WHAT/WHEN/WHY/HOW
Advanced Redux architecture - WHAT/WHEN/WHY/HOWAdvanced Redux architecture - WHAT/WHEN/WHY/HOW
Advanced Redux architecture - WHAT/WHEN/WHY/HOW
 
React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥
 

Recently uploaded

VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girladitipandeya
 
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With RoomVIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Roomgirls4nights
 
VIP Call Girls Pune Madhuri 8617697112 Independent Escort Service Pune
VIP Call Girls Pune Madhuri 8617697112 Independent Escort Service PuneVIP Call Girls Pune Madhuri 8617697112 Independent Escort Service Pune
VIP Call Girls Pune Madhuri 8617697112 Independent Escort Service PuneCall girls in Ahmedabad High profile
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024APNIC
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)Damian Radcliffe
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Sheetaleventcompany
 
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on DeliveryCall Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Deliverybabeytanya
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya Shirtrahman018755
 
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Delhi Call girls
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012rehmti665
 
VIP Kolkata Call Girl Salt Lake 👉 8250192130 Available With Room
VIP Kolkata Call Girl Salt Lake 👉 8250192130  Available With RoomVIP Kolkata Call Girl Salt Lake 👉 8250192130  Available With Room
VIP Kolkata Call Girl Salt Lake 👉 8250192130 Available With Roomishabajaj13
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...Diya Sharma
 
AlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsAlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsThierry TROUIN ☁
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxellan12
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...SofiyaSharma5
 

Recently uploaded (20)

VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
 
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With RoomVIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
 
VIP Call Girls Pune Madhuri 8617697112 Independent Escort Service Pune
VIP Call Girls Pune Madhuri 8617697112 Independent Escort Service PuneVIP Call Girls Pune Madhuri 8617697112 Independent Escort Service Pune
VIP Call Girls Pune Madhuri 8617697112 Independent Escort Service Pune
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
 
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on DeliveryCall Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Call Girls In South Ex 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In South Ex 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICECall Girls In South Ex 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In South Ex 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
 
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
 
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya ShirtChallengers I Told Ya Shirt
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
 
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
 
VIP Kolkata Call Girl Salt Lake 👉 8250192130 Available With Room
VIP Kolkata Call Girl Salt Lake 👉 8250192130  Available With RoomVIP Kolkata Call Girl Salt Lake 👉 8250192130  Available With Room
VIP Kolkata Call Girl Salt Lake 👉 8250192130 Available With Room
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
 
AlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsAlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with Flows
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
 

MobX for dummies

  • 2. MobX is a simple, scalable and battle tested state management solution The philosophy behind MobX is very simple: Anything that can be derived from the application state, should be derived. Automatically.
  • 3.
  • 4. REACT-MOBX React and MobX together are a powerful combination. ‣ React renders the application state by providing mechanisms to translate it into a tree of renderable components. ‣ MobX provides the mechanism to store and update the application state that React then uses.
  • 5. MobX adds observable capabilities to existing data structures like objects, arrays and class instances. Observable ES2016 (ES7) ES5 Usage: ‣ observable(value) ‣ @observable classProperty = value
  • 6. Observer Observer function / decorator can be used to turn ReactJS components into reactive components. It wraps the component's render function in mobx.autorun to make sure that any data that is used during the rendering of a component forces a re-rendering upon change. Observer is available through the separate mobx-react package.
  • 7. Usage: ‣ observer(value) ‣ @observer class className { . . . } Observer STATELESSCOMPONENT STATEFULL COMPONENT
  • 8. Observer and store(s) In order to bind a component and store(s) we can use Provider component. Provider allows to inject passed stores from the child components by using props.
  • 9. Observer adds lifecycle hook When using mobx-react you can define a new life cycle hook, componentWillReact that will be triggered when a component will be scheduled to re-render because data it observes has changed ‣ componentWillReact doesn't take arguments ‣ componentWillReact won't fire before the initial render
 (use componentWillMount instead)
  • 10. When to apply Observer There is a simple rule: all components that render observable data With @observer there is no need to distinguish 'smart' components from 'dumb' components for the purpose of rendering It makes sure that whenever you start using observable data, wrapped component will respond it
  • 11. MobX-React DevTools In combination with @observer you can use the MobX-React DevTools, it shows exactly when your components are re-rendered, also it shows data dependencies of your components
  • 12. MobX-React DevTools VISUALIZE COMPONENT RE-RENDER SHOW COMPONENT DEPENDENCY TREE LOG STATE CHANGES/REACTION
  • 13. Characteristics of Observer component ‣ Observer only subscribe to the data structures that were actively used during the last render. This means that you cannot under- subscribe or over-subscribe. You can even use data in your rendering that will only be available at later moment in time. This is ideal for asynchronously loading data. ‣ You are not required to declare what data a component will use. Instead, dependencies are determined at runtime and tracked in a very fine-grained manner. ‣ Usually reactive components have no or little state, as it is often more convenient to encapsulate (view) state in objects that are shared with other component. But you are still free to use native state. ‣ @observer implements shouldComponentUpdate in the same way as PureRenderMixin so that children are not re-rendered unnecessary. ‣ Reactive components sideways load data. Parent components won't re-render unnecessarily even when child components will. ‣ @observer does not depend on React's context system.
  • 14. Action Any application has actions. Actions are anything that modify the state. With MobX you can make it explicit in your code where your actions live by marking them. Actions help you to structure your code better. Action is advised to use on any function that modifies Observables or has side effects. Action also provides useful debugging information in combination with DevTools Action using action is mandatory when strict mode is enabled
  • 15. Action takes a function as argument and returns it after wrapping it with transaction and allowStateChanges Action Usage: ‣ action(fn) ‣ action(name, fn) ‣ @action classMethod() ‣ @action(name) classMethod()
  • 16. Transaction is a kind of scope of operations. Observer will not notified before transaction will not done Note that transaction runs completely synchronously Transactions can be nested. Only after completing the outer transaction pending reactions will be run Transaction allowStateChanges Can be used to (dis)allow state changes in a certain function. Used internally by action to allow changes, and by computed and observer to disallow state changes.
  • 17. Strict mode Enables / disables strict mode globally. In strict mode, it is not allowed to change any state outside of an action Usage: ‣ useStrict(boolean) Violation consequence:
  • 18. Computed With MobX you can define values that will be derived automatically when relevant data is modified. By using the @computed decorator
  • 19. PropTypes mobx-react provides the following additional PropTypes which can be used to validate against MobX structures: ‣ observableArray ‣ observableArrayOf(React.PropTypes.number) ‣ observableMap ‣ observableObject ‣ arrayOrObservableArray ‣ arrayOrObservableArrayOf(React.PropTypes.number) ‣ objectOrObservableObject Import PropTypes from mobx-react and use it: ‣ PropTypes.observableArray
  • 20. PROS AND CONS Pros: ‣ Makes your components reactive ‣ Easy to understand ‣ Friendly for users with
 OOP background ‣ Less code ‣ Steep learning curve ‣ Responsive community ‣ ?? Magic ?? Cons: ?? Magic ??
  • 21. Useful Links: ‣ Git repo: https://github.com/mobxjs/mobx ‣ Official Documentation: https://mobx.js.org/index.html ‣ MobX Creator on Medium: https://medium.com/@mweststrate ‣ Cheatsheet: http://ricostacruz.com/cheatsheets/mobx.html ‣ Boilerplates: https://mobx.js.org/faq/boilerplates.html Q & A
  • 22. YAUHENI NIKANOVICH Thanks for attention SLIDES: goo.gl/5qSjIt
 EMAIL: zhenyanikon@gmail.com 2017