SlideShare uma empresa Scribd logo
1 de 21
Baixar para ler offline
React.js & Om
A hands-on walkthrough of
better ways to build web UIs
!
!
Adam Solove
March 12, 2014
Who am I?
1998 - First JavaScript
2011 - SiteBuilder
2012 - Dashboard
2013 - ???
2014 - Post Designer
What is React.js?
A responsive html5 MVC framework
What is React.js?
A responsive html5 MVC framework
What is React.js?
Virtual DOM
JSX Templates
Components
What is Om?
Virtual DOM
JSX Templates
Components
Om components
CLJS data structures
Om cursors
CLJS
compiler
Virtual DOM
Virtual DOM
JSX Templates
Components
<ol>
class: ‘people’
<li>
Text: “Bob”
<li>
Text: “Carol”
<li>
Text: “Alice”
DOM diff
Virtual DOM
JSX Templates
Components
<ul>
class: ‘folks’
<li>
Text: “Bob”
<li>
Text: “Carol”
<li>
Text: “Adam”
Synthetic events
Virtual DOM
JSX Templates
Components
<ol>
class: ‘people’
<li>
Text: “Bob”
<li>
Text: “Carol”
<li>
Text: “Alice”
onTap: … onTap: … onTap: …
• Custom event plugins
• Implicit delegation
JSX Templates
Virtual DOM
JSX Templates
Components
• An optional XML syntax
• for creating Virtual DOM trees
• that looks sorta like HTML
• and is optional
JSX Templates
Virtual DOM
JSX Templates
Components
JSX JavaScript
<div className="people"/> React.DOM.div({ className: "people" });
<div>Hello {this.name}</div> React.DOM.div(null, "Hello ", this.name);
<HelloMessage name="John" /> HelloMessage({name: "John"});
<HelloMessage name="John">
<div></div>
<span></span>
</HelloMessage>
HelloMessage({name: "John"},
React.DOM.div(null),
React.DOM.span(null));
Components
Virtual DOM
JSX Templates
Components
• A JavaScript object
• with properties and explicit state
• that can render itself to the DOM
• within a managed life-cycle
Component Object
Virtual DOM
JSX Templates
Components
!
var TodoList = React.createClass({
getInitialState: function() {
return {items: ['prepare talk', ‘charge laptop', 'make fun of rails']};
},
!
handleRemove: function() { /* … */ },
!
render: function() {
var items = this.state.items.map(function(item, i) {
return (
<div key={item} onClick={this.handleRemove.bind(this, i)}>
{item}
</div>
);
}.bind(this));
return (
<div>{items}</div>
);
}
});
Component Data
Virtual DOM
JSX Templates
Components
Only have one authoritative source for each piece of data
!
Two-way bindings are the source of (most) all evil
!
Distinguish multiple readers of data from single writer
!
State v. props
State & Props
Virtual DOM
JSX Templates
Components
TodoList
state: { todos: [{ name: “Make fun of parens”, done: false }]}
props: {}
!
TodoListHeader
props: { done: 0, undone: 1 }
!
TodoItem
props: { item: { name: “Eat pizza”, done: false } }
state: { editing: false }
State has data you own. Props has data you borrow.
You can change your own state. You have to ask someone else to change your props.
Lifecycle methods
Virtual DOM
JSX Templates
Components
Initialization Update Destruction
getInitialState
getDefaultProps
!
componentWillMount
render
componentDidMount
componentWillReceiveProps
shouldComponentUpdate
!
componentWillUpdate
render
componentDidUpdate
componentWillUnmount
The big idea
Virtual DOM
JSX Templates
Components
MVC
DOM
View
Model
React
Data
DOM
What is Om?
Virtual DOM
JSX Templates
Components
Om components
CLJS data structures
Om cursors
CLJS
compiler
Quick CLJS intro
Om components
CLJS data structures
Om cursors
CLJS compiler
Clojure, that compiles to JavaScript, and is still really fast
!
Immutable data structures: [1 2 3] {:a 1 :b 2} #{1 2 3}
!
Some code:
!
(defn contact-view [contact owner]
(reify
om/IRenderState
(render-state [this {:keys [delete]}]
(dom/li nil
(dom/span nil (display-name contact))
(dom/button #js {:onClick (fn [e] (put! delete contact))}
"Delete")))))
Om cursors
Om components
CLJS data structures
Om cursors
CLJS compiler
A piece of data that knows where it is in a data structure
!
(def todos {:todos [
{:done false :text “Make a macro”}
{:done true :text “Confuse the ruby folks”}]})
!
(get-in todos [:todos 0 :done]) #=> false
(update-in todos [:todos 0 :done] not)
#=> new version of todos where first item is done
Om components
Om cursors
CLJS data structures
Om components
CLJS compiler
A React component with a cursor for props
!
(defn my-widget [data owner]
(reify
om/IInitState
(init-state [_]
{:text "Hello world!"})
om/IRenderState
(render-state [_ state]
(dom/h1 nil (:text state)))))

Mais conteúdo relacionado

Mais procurados

jQuery introduction
jQuery introductionjQuery introduction
jQuery introductionTomi Juhola
 
JavaScript APIs you’ve never heard of (and some you have)
JavaScript APIs you’ve never heard of (and some you have)JavaScript APIs you’ve never heard of (and some you have)
JavaScript APIs you’ve never heard of (and some you have)Nicholas Zakas
 
Maintainable JavaScript 2012
Maintainable JavaScript 2012Maintainable JavaScript 2012
Maintainable JavaScript 2012Nicholas Zakas
 
Lesson 203 18 sep13-1500-ay
Lesson 203 18 sep13-1500-ayLesson 203 18 sep13-1500-ay
Lesson 203 18 sep13-1500-ayCodecademy Ren
 
Why and How to Use Virtual DOM
Why and How to Use Virtual DOMWhy and How to Use Virtual DOM
Why and How to Use Virtual DOMDaiwei Lu
 
Write Less Do More
Write Less Do MoreWrite Less Do More
Write Less Do MoreRemy Sharp
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practicesmanugoel2003
 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQueryAngel Ruiz
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuerymanugoel2003
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginningAnis Ahmad
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutesSimon Willison
 
How to write easy-to-test JavaScript
How to write easy-to-test JavaScriptHow to write easy-to-test JavaScript
How to write easy-to-test JavaScriptYnon Perek
 
jQuery Presentation to Rails Developers
jQuery Presentation to Rails DevelopersjQuery Presentation to Rails Developers
jQuery Presentation to Rails DevelopersYehuda Katz
 
JavaScript and jQuery Basics
JavaScript and jQuery BasicsJavaScript and jQuery Basics
JavaScript and jQuery BasicsKaloyan Kosev
 

Mais procurados (20)

jQuery introduction
jQuery introductionjQuery introduction
jQuery introduction
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
jQuery
jQueryjQuery
jQuery
 
JavaScript APIs you’ve never heard of (and some you have)
JavaScript APIs you’ve never heard of (and some you have)JavaScript APIs you’ve never heard of (and some you have)
JavaScript APIs you’ve never heard of (and some you have)
 
jQuery
jQueryjQuery
jQuery
 
jQuery Introduction
jQuery IntroductionjQuery Introduction
jQuery Introduction
 
Maintainable JavaScript 2012
Maintainable JavaScript 2012Maintainable JavaScript 2012
Maintainable JavaScript 2012
 
Lesson 203 18 sep13-1500-ay
Lesson 203 18 sep13-1500-ayLesson 203 18 sep13-1500-ay
Lesson 203 18 sep13-1500-ay
 
Why and How to Use Virtual DOM
Why and How to Use Virtual DOMWhy and How to Use Virtual DOM
Why and How to Use Virtual DOM
 
Write Less Do More
Write Less Do MoreWrite Less Do More
Write Less Do More
 
Jquery
JqueryJquery
Jquery
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQuery
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
 
Lecture 5: Client Side Programming 1
Lecture 5: Client Side Programming 1Lecture 5: Client Side Programming 1
Lecture 5: Client Side Programming 1
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutes
 
How to write easy-to-test JavaScript
How to write easy-to-test JavaScriptHow to write easy-to-test JavaScript
How to write easy-to-test JavaScript
 
jQuery Presentation to Rails Developers
jQuery Presentation to Rails DevelopersjQuery Presentation to Rails Developers
jQuery Presentation to Rails Developers
 
JavaScript and jQuery Basics
JavaScript and jQuery BasicsJavaScript and jQuery Basics
JavaScript and jQuery Basics
 

Destaque

Rails Request & Middlewares
Rails Request & MiddlewaresRails Request & Middlewares
Rails Request & MiddlewaresSantosh Wadghule
 
Rails Request Response Lifecycle
Rails Request Response LifecycleRails Request Response Lifecycle
Rails Request Response LifecycleIvan Storck
 
Request-Response Cycle of Ruby on Rails App
Request-Response Cycle of Ruby on Rails AppRequest-Response Cycle of Ruby on Rails App
Request-Response Cycle of Ruby on Rails AppNathalie Steinmetz
 
Web : Request-Response Lifecycle (Ruby on Rails)
Web : Request-Response Lifecycle (Ruby on Rails)Web : Request-Response Lifecycle (Ruby on Rails)
Web : Request-Response Lifecycle (Ruby on Rails)Rakesh Jha
 
How We Do DevOps at Walmart: OneOps OSS Application Lifecycle Management Plat...
How We Do DevOps at Walmart: OneOps OSS Application Lifecycle Management Plat...How We Do DevOps at Walmart: OneOps OSS Application Lifecycle Management Plat...
How We Do DevOps at Walmart: OneOps OSS Application Lifecycle Management Plat...WalmartLabs
 
Make GUI Apps with Shoes
Make GUI Apps with ShoesMake GUI Apps with Shoes
Make GUI Apps with ShoesBrian Hogan
 
Ruby application based on http
Ruby application based on httpRuby application based on http
Ruby application based on httpRichard Huang
 
Deployment with Ruby on Rails
Deployment with Ruby on RailsDeployment with Ruby on Rails
Deployment with Ruby on RailsJonathan Weiss
 
Developing cross platform desktop application with Ruby
Developing cross platform desktop application with RubyDeveloping cross platform desktop application with Ruby
Developing cross platform desktop application with RubyAnis Ahmad
 
The Case for React.js and ClojureScript
The Case for React.js and ClojureScriptThe Case for React.js and ClojureScript
The Case for React.js and ClojureScriptMurilo Pereira
 

Destaque (13)

How to use React.js
How to use React.jsHow to use React.js
How to use React.js
 
React.js at Cortex
React.js at CortexReact.js at Cortex
React.js at Cortex
 
Rails Request & Middlewares
Rails Request & MiddlewaresRails Request & Middlewares
Rails Request & Middlewares
 
Rails Request Response Lifecycle
Rails Request Response LifecycleRails Request Response Lifecycle
Rails Request Response Lifecycle
 
React JS - Introduction
React JS - IntroductionReact JS - Introduction
React JS - Introduction
 
Request-Response Cycle of Ruby on Rails App
Request-Response Cycle of Ruby on Rails AppRequest-Response Cycle of Ruby on Rails App
Request-Response Cycle of Ruby on Rails App
 
Web : Request-Response Lifecycle (Ruby on Rails)
Web : Request-Response Lifecycle (Ruby on Rails)Web : Request-Response Lifecycle (Ruby on Rails)
Web : Request-Response Lifecycle (Ruby on Rails)
 
How We Do DevOps at Walmart: OneOps OSS Application Lifecycle Management Plat...
How We Do DevOps at Walmart: OneOps OSS Application Lifecycle Management Plat...How We Do DevOps at Walmart: OneOps OSS Application Lifecycle Management Plat...
How We Do DevOps at Walmart: OneOps OSS Application Lifecycle Management Plat...
 
Make GUI Apps with Shoes
Make GUI Apps with ShoesMake GUI Apps with Shoes
Make GUI Apps with Shoes
 
Ruby application based on http
Ruby application based on httpRuby application based on http
Ruby application based on http
 
Deployment with Ruby on Rails
Deployment with Ruby on RailsDeployment with Ruby on Rails
Deployment with Ruby on Rails
 
Developing cross platform desktop application with Ruby
Developing cross platform desktop application with RubyDeveloping cross platform desktop application with Ruby
Developing cross platform desktop application with Ruby
 
The Case for React.js and ClojureScript
The Case for React.js and ClojureScriptThe Case for React.js and ClojureScript
The Case for React.js and ClojureScript
 

Semelhante a React.js & Om: A hands-on walkthrough of better ways to build web UIs

Web Components + Backbone: a Game-Changing Combination
Web Components + Backbone: a Game-Changing CombinationWeb Components + Backbone: a Game-Changing Combination
Web Components + Backbone: a Game-Changing CombinationAndrew Rota
 
Intro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScriptIntro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScriptjasonsich
 
React js - The Core Concepts
React js - The Core ConceptsReact js - The Core Concepts
React js - The Core ConceptsDivyang Bhambhani
 
Building Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript SpaghettiBuilding Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript SpaghettiJared Faris
 
Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016Marco Breveglieri
 
Node.js introduction
Node.js introductionNode.js introduction
Node.js introductionParth Joshi
 
NinjaScript 2010-10-14
NinjaScript 2010-10-14NinjaScript 2010-10-14
NinjaScript 2010-10-14lrdesign
 
JavaScript front end performance optimizations
JavaScript front end performance optimizationsJavaScript front end performance optimizations
JavaScript front end performance optimizationsChris Love
 
JS Libraries and jQuery Overview
JS Libraries and jQuery OverviewJS Libraries and jQuery Overview
JS Libraries and jQuery OverviewAleksandr Motsjonov
 
2018 02-22 React, Redux & Building Applications that Scale | React
2018 02-22 React, Redux & Building Applications that Scale | React2018 02-22 React, Redux & Building Applications that Scale | React
2018 02-22 React, Redux & Building Applications that Scale | ReactCodifly
 
Why Nodejs Guilin Shanghai
Why Nodejs Guilin ShanghaiWhy Nodejs Guilin Shanghai
Why Nodejs Guilin ShanghaiJackson Tian
 
Why Node.js
Why Node.jsWhy Node.js
Why Node.jsguileen
 
The Art and Science of Shipping Ember Apps
The Art and Science of Shipping Ember AppsThe Art and Science of Shipping Ember Apps
The Art and Science of Shipping Ember AppsJesse Cravens
 
20150309 seven core principles of meteor
20150309 seven core principles of meteor20150309 seven core principles of meteor
20150309 seven core principles of meteorRick Wehrle
 
React && React Native workshop
React && React Native workshopReact && React Native workshop
React && React Native workshopStacy Goh
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationAndrew Rota
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery PresentationRod Johnson
 
Canopy view of single-page applications (SPAs)
Canopy view of single-page applications (SPAs)Canopy view of single-page applications (SPAs)
Canopy view of single-page applications (SPAs)Benjamin Howarth
 

Semelhante a React.js & Om: A hands-on walkthrough of better ways to build web UIs (20)

Web Components + Backbone: a Game-Changing Combination
Web Components + Backbone: a Game-Changing CombinationWeb Components + Backbone: a Game-Changing Combination
Web Components + Backbone: a Game-Changing Combination
 
Intro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScriptIntro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScript
 
React js - The Core Concepts
React js - The Core ConceptsReact js - The Core Concepts
React js - The Core Concepts
 
Building Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript SpaghettiBuilding Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript Spaghetti
 
Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016
 
Node.js introduction
Node.js introductionNode.js introduction
Node.js introduction
 
NinjaScript 2010-10-14
NinjaScript 2010-10-14NinjaScript 2010-10-14
NinjaScript 2010-10-14
 
JavaScript front end performance optimizations
JavaScript front end performance optimizationsJavaScript front end performance optimizations
JavaScript front end performance optimizations
 
JS Libraries and jQuery Overview
JS Libraries and jQuery OverviewJS Libraries and jQuery Overview
JS Libraries and jQuery Overview
 
Web 2.0
Web 2.0Web 2.0
Web 2.0
 
2018 02-22 React, Redux & Building Applications that Scale | React
2018 02-22 React, Redux & Building Applications that Scale | React2018 02-22 React, Redux & Building Applications that Scale | React
2018 02-22 React, Redux & Building Applications that Scale | React
 
Why Nodejs Guilin Shanghai
Why Nodejs Guilin ShanghaiWhy Nodejs Guilin Shanghai
Why Nodejs Guilin Shanghai
 
Why Node.js
Why Node.jsWhy Node.js
Why Node.js
 
The Art and Science of Shipping Ember Apps
The Art and Science of Shipping Ember AppsThe Art and Science of Shipping Ember Apps
The Art and Science of Shipping Ember Apps
 
20150309 seven core principles of meteor
20150309 seven core principles of meteor20150309 seven core principles of meteor
20150309 seven core principles of meteor
 
React && React Native workshop
React && React Native workshopReact && React Native workshop
React && React Native workshop
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP Application
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery Presentation
 
Canopy view of single-page applications (SPAs)
Canopy view of single-page applications (SPAs)Canopy view of single-page applications (SPAs)
Canopy view of single-page applications (SPAs)
 
jQuery quick tips
jQuery quick tipsjQuery quick tips
jQuery quick tips
 

Último

SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 

Último (20)

SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

React.js & Om: A hands-on walkthrough of better ways to build web UIs

  • 1. React.js & Om A hands-on walkthrough of better ways to build web UIs ! ! Adam Solove March 12, 2014
  • 2. Who am I? 1998 - First JavaScript 2011 - SiteBuilder 2012 - Dashboard 2013 - ??? 2014 - Post Designer
  • 3. What is React.js? A responsive html5 MVC framework
  • 4. What is React.js? A responsive html5 MVC framework
  • 5. What is React.js? Virtual DOM JSX Templates Components
  • 6. What is Om? Virtual DOM JSX Templates Components Om components CLJS data structures Om cursors CLJS compiler
  • 7. Virtual DOM Virtual DOM JSX Templates Components <ol> class: ‘people’ <li> Text: “Bob” <li> Text: “Carol” <li> Text: “Alice”
  • 8. DOM diff Virtual DOM JSX Templates Components <ul> class: ‘folks’ <li> Text: “Bob” <li> Text: “Carol” <li> Text: “Adam”
  • 9. Synthetic events Virtual DOM JSX Templates Components <ol> class: ‘people’ <li> Text: “Bob” <li> Text: “Carol” <li> Text: “Alice” onTap: … onTap: … onTap: … • Custom event plugins • Implicit delegation
  • 10. JSX Templates Virtual DOM JSX Templates Components • An optional XML syntax • for creating Virtual DOM trees • that looks sorta like HTML • and is optional
  • 11. JSX Templates Virtual DOM JSX Templates Components JSX JavaScript <div className="people"/> React.DOM.div({ className: "people" }); <div>Hello {this.name}</div> React.DOM.div(null, "Hello ", this.name); <HelloMessage name="John" /> HelloMessage({name: "John"}); <HelloMessage name="John"> <div></div> <span></span> </HelloMessage> HelloMessage({name: "John"}, React.DOM.div(null), React.DOM.span(null));
  • 12. Components Virtual DOM JSX Templates Components • A JavaScript object • with properties and explicit state • that can render itself to the DOM • within a managed life-cycle
  • 13. Component Object Virtual DOM JSX Templates Components ! var TodoList = React.createClass({ getInitialState: function() { return {items: ['prepare talk', ‘charge laptop', 'make fun of rails']}; }, ! handleRemove: function() { /* … */ }, ! render: function() { var items = this.state.items.map(function(item, i) { return ( <div key={item} onClick={this.handleRemove.bind(this, i)}> {item} </div> ); }.bind(this)); return ( <div>{items}</div> ); } });
  • 14. Component Data Virtual DOM JSX Templates Components Only have one authoritative source for each piece of data ! Two-way bindings are the source of (most) all evil ! Distinguish multiple readers of data from single writer ! State v. props
  • 15. State & Props Virtual DOM JSX Templates Components TodoList state: { todos: [{ name: “Make fun of parens”, done: false }]} props: {} ! TodoListHeader props: { done: 0, undone: 1 } ! TodoItem props: { item: { name: “Eat pizza”, done: false } } state: { editing: false } State has data you own. Props has data you borrow. You can change your own state. You have to ask someone else to change your props.
  • 16. Lifecycle methods Virtual DOM JSX Templates Components Initialization Update Destruction getInitialState getDefaultProps ! componentWillMount render componentDidMount componentWillReceiveProps shouldComponentUpdate ! componentWillUpdate render componentDidUpdate componentWillUnmount
  • 17. The big idea Virtual DOM JSX Templates Components MVC DOM View Model React Data DOM
  • 18. What is Om? Virtual DOM JSX Templates Components Om components CLJS data structures Om cursors CLJS compiler
  • 19. Quick CLJS intro Om components CLJS data structures Om cursors CLJS compiler Clojure, that compiles to JavaScript, and is still really fast ! Immutable data structures: [1 2 3] {:a 1 :b 2} #{1 2 3} ! Some code: ! (defn contact-view [contact owner] (reify om/IRenderState (render-state [this {:keys [delete]}] (dom/li nil (dom/span nil (display-name contact)) (dom/button #js {:onClick (fn [e] (put! delete contact))} "Delete")))))
  • 20. Om cursors Om components CLJS data structures Om cursors CLJS compiler A piece of data that knows where it is in a data structure ! (def todos {:todos [ {:done false :text “Make a macro”} {:done true :text “Confuse the ruby folks”}]}) ! (get-in todos [:todos 0 :done]) #=> false (update-in todos [:todos 0 :done] not) #=> new version of todos where first item is done
  • 21. Om components Om cursors CLJS data structures Om components CLJS compiler A React component with a cursor for props ! (defn my-widget [data owner] (reify om/IInitState (init-state [_] {:text "Hello world!"}) om/IRenderState (render-state [_ state] (dom/h1 nil (:text state)))))