SlideShare a Scribd company logo
1 of 49
Download to read offline
MobX -
Performance and Sanity
RECORD SCREEN
Adam Klein
CTO @ 500Tech
https://www.meetup.com/Angular-IL
Taking the state out of
components
Items Filter
Checkbox
List
Filter
Add New
Selected
Items
Remove
Item
Input
Selected
Item
App
State
Components
State
Easy as pie
import service from ‘myService’;
// call service.action()
// use service.state
Problem Solved!
toggle item
Selected Items Master Checkbox
toggle master
Filtered Items
add item change filter
Imperative
Declarative
Declarative
<div *ngFor="let item of state.filteredItems”>

{{ item.title }}

</div>
Declarative
<div *ngFor="let item of state.getFilteredItems()">

{{ item.title }}

</div>

getFilteredItems() {

const regexp = new RegExp(this.filter, 'i');



return this.items
.filter((item) => regexp.test(item.name));

}
Declarative
getFilteredItems() {

const regexp = new RegExp(this.filter, 'i');



return this.items
.filter((item) => regexp.test(item.name));

}
Declarative
The ideal state
Memoizes derived values
Selectively Update UI
React to changes
The ideal state
Memoizes derived values
Selectively Update UI
React to changes
The ideal state
Memoizes derived values
Selectively Update UI
React to changes
MobX
MobX
Michel Weststrate from Mendix
Michel Weststrate from Mendix
React + Angular connectors
MobX
Michel Weststrate from Mendix
React + Angular connectors
Automagically react to changes
MobX
Michel Weststrate from Mendix
React + Angular connectors
Automagically react to changes
Works with plain objects
MobX
Michel Weststrate from Mendix
React + Angular connectors
Automagically react to changes
Works with plain objects
MobX
List of
Frameworks
Selected
Items
Filter
Master
Checkbox
Filtered
Items
Selected Items Filter ComponentUI Components
Store
Observables Computed Values
Reactions
FriendsMessages
News FeedTopbar
UI Components
Stores
Sidebar
Feed
Posts Comments


class Store {

filter = '';

items = [];

}
Store - it’s just a class!


class Store {

filter = '';

items = [];

}
ES6 + Class properties
import { observable } from 'mobx';

class Store {

@observable filter = '';

@observable items = [];

}
Observable
…
getFilteredItems() {

const regexp = new RegExp(this.filter, 'i');



return this.items
.filter((item) => regexp.test(item.name));

}
…
Derived State
import { computed } from 'mobx';

@computed get filteredItems() {

const regexp = new RegExp(this.filter, 'i');



return this.items
.filter((item) => regexp.test(item.name));

}
…
Computed
…
@computed get filteredItems() {

const regexp = new RegExp(this.filter, 'i');



return this.items
.filter((item) => regexp.test(item.name));

}
…
Figures dependencies automatically
…
setFilter(value) {

this.filter = value;

}

…
Action - it’s just setting a property
…
setFilter(value) {

this.filter = value;

}

…
Action
…
@action setFilter(value) {

this.filter = value;

}

…
Action
…
@action addItem(item) {

this.items.push(item);

}

…
Works with array methods
class Store {

@observable filter = '';

@observable items = [];

@computed get filteredItems() {

const regexp = new RegExp(this.filter, 'i');



return this.items.filter((item) => regexp.test(item.name));

}
@action setFilter(value) {

this.filter = value;

}

@action addItem(item) {

this.items.push(item);

}

}
autorun(() => {

const items = store.filteredItems;



renderItemsOnDOM(items);

});
Automatic Reaction
Update UI automatically
autorun(() => {

const items = store.filteredItems;



renderItemsOnDOM(items);

});
Connectors
mobx-react, mobx-angular
Automatically re-renders on changes
class TodoView extends React.Component {

render() {

return <div>{ store.filteredItems }</div>

}

}
mobx-react
https://github.com/mobxjs/mobx-react
@observer class TodoView extends React.Component {

render() {

return <div>{ store.filteredItems }</div>

}

}
mobx-react
https://github.com/mobxjs/mobx-react
<div>

{{ store.filteredItems }}
</div>
mobx-angular
https://github.com/mobxjs/mobx-angular
<div *mobxAutorun>

{{ store.filteredItems }}

</div>
mobx-angular
https://github.com/mobxjs/mobx-angular
<div mobx-autorun>

{{ store.filteredItems }}

</div>
ng-mobx for Angular1
https://github.com/NgMobx/ng1-mobx
MobX Redux
Plain objects
OOD
Immutable data
FP
Automatic Explicit
Computed values Using reselect
Multiple Stores Single Store
Use Async regularly Async is trouble
Complex library, Simple code Simple library, Complex code
Debugging methods
Spy
Explicit reactions
Compare function
And more…
There’s more to it…
slidehare.net/500tech
@adamklein500
Thank You
mobxjs.github.io/mobx/

More Related Content

What's hot

LinkedIn TBC JavaScript 100: Functions
 LinkedIn TBC JavaScript 100: Functions LinkedIn TBC JavaScript 100: Functions
LinkedIn TBC JavaScript 100: Functions
Adam Crabtree
 
Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Developing A Real World Logistic Application With Oracle Application - UKOUG ...Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Roel Hartman
 

What's hot (20)

React lecture
React lectureReact lecture
React lecture
 
Talk about Testing at vienna.rb meetup #2 on Apr 12th, 2013
Talk about Testing at vienna.rb meetup #2 on Apr 12th, 2013Talk about Testing at vienna.rb meetup #2 on Apr 12th, 2013
Talk about Testing at vienna.rb meetup #2 on Apr 12th, 2013
 
activity_and_fragment_may_2020_lakopi
activity_and_fragment_may_2020_lakopiactivity_and_fragment_may_2020_lakopi
activity_and_fragment_may_2020_lakopi
 
Code craftsmanship saturdays second session
Code craftsmanship saturdays second sessionCode craftsmanship saturdays second session
Code craftsmanship saturdays second session
 
Cambio de bases
Cambio de basesCambio de bases
Cambio de bases
 
Testowanie JavaScript
Testowanie JavaScriptTestowanie JavaScript
Testowanie JavaScript
 
Rxjs swetugg
Rxjs swetuggRxjs swetugg
Rxjs swetugg
 
Rxjs ppt
Rxjs pptRxjs ppt
Rxjs ppt
 
Ngrx: Redux in angular
Ngrx: Redux in angularNgrx: Redux in angular
Ngrx: Redux in angular
 
Java script
Java scriptJava script
Java script
 
Angular mix chrisnoring
Angular mix chrisnoringAngular mix chrisnoring
Angular mix chrisnoring
 
How to practice functional programming in react
How to practice functional programming in reactHow to practice functional programming in react
How to practice functional programming in react
 
LinkedIn TBC JavaScript 100: Functions
 LinkedIn TBC JavaScript 100: Functions LinkedIn TBC JavaScript 100: Functions
LinkedIn TBC JavaScript 100: Functions
 
Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Developing A Real World Logistic Application With Oracle Application - UKOUG ...Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Developing A Real World Logistic Application With Oracle Application - UKOUG ...
 
Nativescript angular
Nativescript angularNativescript angular
Nativescript angular
 
React new features and intro to Hooks
React new features and intro to HooksReact new features and intro to Hooks
React new features and intro to Hooks
 
Creating sub zero dashboard plugin for apex with google
Creating sub zero dashboard plugin for apex with googleCreating sub zero dashboard plugin for apex with google
Creating sub zero dashboard plugin for apex with google
 
Higher Order Components and Render Props
Higher Order Components and Render PropsHigher Order Components and Render Props
Higher Order Components and Render Props
 
Formal methods Project Report for the support of slides uploaded
Formal methods Project Report for the support of slides uploaded Formal methods Project Report for the support of slides uploaded
Formal methods Project Report for the support of slides uploaded
 
Check the output of the following code then recode it to eliminate fu
 Check the output of the following code then recode it to eliminate fu Check the output of the following code then recode it to eliminate fu
Check the output of the following code then recode it to eliminate fu
 

Similar to Mobx - performance and sanity

Converting Db Schema Into Uml Classes
Converting Db Schema Into Uml ClassesConverting Db Schema Into Uml Classes
Converting Db Schema Into Uml Classes
Kaniska Mandal
 
13 advanced-swing
13 advanced-swing13 advanced-swing
13 advanced-swing
Nataraj Dg
 
package net.codejava.swing.mail;import java.awt.Font;import java.pdf
package net.codejava.swing.mail;import java.awt.Font;import java.pdfpackage net.codejava.swing.mail;import java.awt.Font;import java.pdf
package net.codejava.swing.mail;import java.awt.Font;import java.pdf
sudhirchourasia86
 
12advanced Swing
12advanced Swing12advanced Swing
12advanced Swing
Adil Jafri
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Thomas Fuchs
 
Evan Schultz - Angular Camp - ng2-redux
Evan Schultz - Angular Camp - ng2-reduxEvan Schultz - Angular Camp - ng2-redux
Evan Schultz - Angular Camp - ng2-redux
Evan Schultz
 

Similar to Mobx - performance and sanity (20)

React performance tips, Тельман Агабабов
React performance tips, Тельман АгабабовReact performance tips, Тельман Агабабов
React performance tips, Тельман Агабабов
 
Ngrx meta reducers
Ngrx meta reducersNgrx meta reducers
Ngrx meta reducers
 
Converting Db Schema Into Uml Classes
Converting Db Schema Into Uml ClassesConverting Db Schema Into Uml Classes
Converting Db Schema Into Uml Classes
 
React hooks
React hooksReact hooks
React hooks
 
Android Design Patterns
Android Design PatternsAndroid Design Patterns
Android Design Patterns
 
How te bring common UI patterns to ADF
How te bring common UI patterns to ADFHow te bring common UI patterns to ADF
How te bring common UI patterns to ADF
 
13 advanced-swing
13 advanced-swing13 advanced-swing
13 advanced-swing
 
Intro to React | DreamLab Academy
Intro to React | DreamLab AcademyIntro to React | DreamLab Academy
Intro to React | DreamLab Academy
 
Building complex User Interfaces with Sitecore and React
Building complex User Interfaces with Sitecore and ReactBuilding complex User Interfaces with Sitecore and React
Building complex User Interfaces with Sitecore and React
 
Scala on Your Phone
Scala on Your PhoneScala on Your Phone
Scala on Your Phone
 
package net.codejava.swing.mail;import java.awt.Font;import java.pdf
package net.codejava.swing.mail;import java.awt.Font;import java.pdfpackage net.codejava.swing.mail;import java.awt.Font;import java.pdf
package net.codejava.swing.mail;import java.awt.Font;import java.pdf
 
Java Assignment Help
Java Assignment HelpJava Assignment Help
Java Assignment Help
 
How to Bring Common UI Patterns to ADF
How to Bring Common UI Patterns to ADF How to Bring Common UI Patterns to ADF
How to Bring Common UI Patterns to ADF
 
React 16: new features and beyond
React 16: new features and beyondReact 16: new features and beyond
React 16: new features and beyond
 
React redux
React reduxReact redux
React redux
 
12advanced Swing
12advanced Swing12advanced Swing
12advanced Swing
 
08 Queries
08 Queries08 Queries
08 Queries
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
 
Clean Javascript
Clean JavascriptClean Javascript
Clean Javascript
 
Evan Schultz - Angular Camp - ng2-redux
Evan Schultz - Angular Camp - ng2-reduxEvan Schultz - Angular Camp - ng2-redux
Evan Schultz - Angular Camp - ng2-redux
 

More from 500Tech

More from 500Tech (20)

State managment in a world of hooks
State managment in a world of hooksState managment in a world of hooks
State managment in a world of hooks
 
State managment in a world of hooks
State managment in a world of hooksState managment in a world of hooks
State managment in a world of hooks
 
React Under the Hook - DevDays Europe 2019
React Under the Hook - DevDays Europe 2019React Under the Hook - DevDays Europe 2019
React Under the Hook - DevDays Europe 2019
 
React Back to the Future
React Back to the FutureReact Back to the Future
React Back to the Future
 
Hooks - why should you care today?
Hooks - why should you care today?Hooks - why should you care today?
Hooks - why should you care today?
 
Migrating from angular to react
Migrating from angular to reactMigrating from angular to react
Migrating from angular to react
 
How to write bad code in redux (ReactNext 2018)
How to write bad code in redux (ReactNext 2018)How to write bad code in redux (ReactNext 2018)
How to write bad code in redux (ReactNext 2018)
 
Opinionated Approach to Redux
Opinionated Approach to ReduxOpinionated Approach to Redux
Opinionated Approach to Redux
 
Mobx Internals
Mobx InternalsMobx Internals
Mobx Internals
 
Mobx - Performance and Sanity
Mobx - Performance and SanityMobx - Performance and Sanity
Mobx - Performance and Sanity
 
Tales of an open source library
Tales of an open source libraryTales of an open source library
Tales of an open source library
 
Angular2 a modern web platform
Angular2   a modern web platformAngular2   a modern web platform
Angular2 a modern web platform
 
Angular. MobX. Happiness
Angular. MobX. HappinessAngular. MobX. Happiness
Angular. MobX. Happiness
 
Render to DOM
Render to DOMRender to DOM
Render to DOM
 
Managing state in Angular 1.x with Redux
Managing state in Angular 1.x with ReduxManaging state in Angular 1.x with Redux
Managing state in Angular 1.x with Redux
 
React vs angular
React vs angularReact vs angular
React vs angular
 
D3 svg & angular
D3 svg & angularD3 svg & angular
D3 svg & angular
 
ReactJS vs AngularJS - Head to Head comparison
ReactJS vs AngularJS - Head to Head comparisonReactJS vs AngularJS - Head to Head comparison
ReactJS vs AngularJS - Head to Head comparison
 
Understanding Redux — Ilya Gelman
Understanding Redux — Ilya GelmanUnderstanding Redux — Ilya Gelman
Understanding Redux — Ilya Gelman
 
Js tests like a pro
Js tests like a proJs tests like a pro
Js tests like a pro
 

Recently uploaded

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Recently uploaded (20)

call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 

Mobx - performance and sanity