SlideShare a Scribd company logo
1 of 51
Download to read offline
Reconciling React as a
View Layer Replacement
Zach Lendon
@zachlendon
#reactjs #midwestjs
#reactjsisawesome
https://github.com/zachlendon/midwestjs2014
Traditional JS
MV* “issues”
•“State”
•Performance
•Complexity
•Predictability
•Testability
• Isomorphic Javascript
• The right simple :: powerful ratio
• The right configurable :: opinionated
ratio
• Pluggable modular architecture
• Performant
• SEO
Top keys to future “web” MV*
framework success
“State” of the JS MV*
Meet React
•A Javascript Library for Creating User Interfaces
•https://github.com/facebook/react
•Open Sourced and Battle-tested by Facebook and
Instagram
•Browser support to IE8
“React is not a full MVC framework, and this is actually one of its
strengths. Many who adopt React choose to do so alongside their
favorite MVC framework, like Backbone. React has no opinions
about routing or syncing data, so you can easily use your favorite
tools to handle those aspects of your frontend application. You'll
often see React used to manage specific parts of an application's UI
and not others. React really shines, however, when you fully
embrace its strategies and make it the core of your application's
interface.”
@bkonkle: http://lincolnloop.com/blog/architecting-your-app-react-part-1/
Why React?
• “State” is what makes building UIs hard
• “Data Changing over time is the Root of All Evil”
React Solution
Use composable React components that effectively
re-render themselves on each state mutation
•Apple
•Oranges
•Apple
•Grapes
•Bananas
React
Before After
Virtual DOM
•In-memory representation of the DOM and
events system
•Even HTML5 events in IE8
Advantages of Virtual DOM
•Interacting with DOM -> Slow,
•with Javascript In-Memory Objects -> fast
•60 fps fast
•Faster parsing
•Faster Validation
•Since no real browser, can easily render on server or
client
•Easier To Test
Fallout Advantages of Virtual DOM include
•Autobinding
•Event Delegation
http://lincolnloop.com/blog/architecting-your-app-react-part-1/
React Components
React Components translate raw data into rich HTML
The Ultimate State Machine
React Components
React.createClass({..})
The Ultimate State Machine
Render: “pure” Javascript function
http://jsfiddle.net/zlendon/9xyn3/
Render: “pure” Coffeescript function
http://jsfiddle.net/zlendon/32xj5/
Render: Better “pure” Coffeescript function
http://jsfiddle.net/zlendon/32xj5/1/
Render: “JSX” Javascript function
http://jsfiddle.net/zH5YG/
JSX “Desugared” to native Javascript
Rules of Render
•Return a single child component
•Native DOM component
•Composite Component
•Return predictable result each time invoked
•Does not touch the DOM (read or write) or interact with the
browser (i.e., setTimeout)
!
Rules of Server Side Render
!
!
!
!
•renderComponentToString on server
•render on client, to same node, preserves server-rendered
markup and adds event handlers
•http://www.princeton.edu/~crmarsh/react-ssr/
(Charlie Marsh)
•https://github.com/andreypopp/react-async
•https://github.com/karlmikko/bleeding-edge-
sample-app/blob/react-router/server/render/
render.js (soon to be in React-Router)
tl&dr;
React Components: Input
•Props: immutable data specific to an instance of a
component
•Like params into a function
•State: Private mutable attribute. Change within
which trigger scheduling of a component re-render
Both Props and State
• Are plain JS objects
• Changes trigger a render update
• Are deterministic. If your Component generates different outputs for
the same combination of props and state then you're doing something
wrong.
https://github.com/uberVU/react-guide/blob/master/props-vs-state.md#readme
Rules of State
•Belong to only one component
•Within that component, modified 2 ways
•getInitialState
•setState
•Render returns same result each time invoked with same
state
•Do not use computed data or duplicate prop data as state
•Avoid using state when possible
•Do not change state of children components
Rules of Props
•Passed from the parent
•Immutable
•Often pass callback functions through them
!
Component Lifecycle
Mounting
• componentWillMount()
• componentDidMount()
!
Updating
• componentWillReceiveProps(object nextProps)
• boolean shouldComponentUpdate(object nextProps, object nextState)
• componentWillUpdate(object nextProps, object nextState)
• componentDidUpdate(object prevProps, object prevState)
!
Unmounting
• componentWillUnmount()
Mixins
•Cross cutting concerns
•Examples:
•ReactScriptLoader: https://github.com/yariv/ReactScriptLoader
•ReactIntlMixin: https://github.com/yahoo/react-intl
•Backbone.React.Component.mixin: https://github.com/
magalhas/backbone-react-component
Scaling React
!
!
!
!
Action Controller Model View
Conference MVC
• Modified from Flux into by Jing Chen at F8, 2014
Scaling with React
!
!
!
!
Action Controller Model View
Model
Model
Model
Model
Model
View
View
View
View
View
View
Real World MVC
Scaling with React
!
!
!
!
Action Dispatcher Store View
Action
Flux
Starting a New App: React
•Lots of Great “Full-Stack” Starter Kit Options - Many Listed:
https://github.com/facebook/react/wiki/Complementary-Tools
New Project w/ Routing
•React Boilerplate: https://github.com/rackt/react-boilerplate
•Uses:
•React-router (prev. react-nested-router)
•Translation of Ember Router API to React
•Webpack
•pushstate-serv
New Project w/o Routing
•https://github.com/newtriks/generator-react-webpack
•Yeoman Generator
•Uses:
•Webpack
•Grunt
•Karma
New Project w/ Routing & Server-side Rendering:
•React Quickstart:
•https://github.com/newtriks/generator-react-webpack
•Uses:
•react-router-component
•react-async
•express
•browserify
•npm
New Project: Midwest JS Demo
•React Boilerplate
•Plus:
•Express (3)
•Bootstrap 3
DEMO DISCUSSION
Adding React To Existing Project
“We don’t need to switch to React everywhere, all at once. It’s
not a framework that imposes anything on the application
structure. [...] Easy, iterative adoption is definitely something
in React’s favor for us.”
!
-Adobe Brackets Team
Backbone Views
•Nested Backbone.View’s are difficult to maintain
•Every collection change re-renders all views
Simple Backbone Port
Integration with Backbone Models and Collections
•Trigger React re-render on Backbone model “change” events
Mixins! Maybe
Lost shouldComponentUpdate hooks
TODO MVC: React + Backbone
Mixins! Maybe
Backbone-React-Component
Mixins! Maybe
Backbone-React-Component
Use State Callback
Use State Callback
Angular and React
Angular Directives Wrapping React
•ngReact
•ngReactGrid
Angular ngReactGrid Demo
Integration Lessons
•You can integrate React with other frameworks
•Backbone integration works better than many options since re-
rendering on model state change is the typical Backbone
approach
•Angular will work best from directives but is a bit of a force fit
•Best approach to let React own the DOM element being
rendered into
(Beyond the Obvious) Additional Resources (1/2)
•Great Collection of Community links:

https://github.com/mindreframer/reactjs-stuff
•Developing User Interfaces with React: http://youtu.be/
1OeXsL5mr4g?list=PLuE9Gq9Mxr5kCvVa7tcwW1S2-FEym5fbt
(intro + good performance demo)
•Good Flux intro by Ryan Florence: http://vimeo.com/
102953099
•Thorough and infamous Angular/ReactJS performance/
integration post: http://www.williambrownstreet.net/blog/
2014/04/faster-angularjs-rendering-angularjs-and-reactjs/
•Performance Tools: http://facebook.github.io/react/docs/
perf.html
!
(Beyond the Obvious) Additional Resources (2/2)
!
•Webpack Howto: https://github.com/petehunt/webpack-
howto
•Webpack Hot Module Replacement: https://github.com/
webpack/docs/wiki/hot-module-replacement-with-webpack
•Om: https://github.com/swannodette/om
•Jest: http://facebook.github.io/jest/
Thank You
Questions?
Zach Lendon
@zachlendon
#reactjs #midwestjs
https://github.com/zachlendon
#reactjs on freenode

More Related Content

What's hot

Isomorphic JavaScript – future of the web
Isomorphic JavaScript – future of the webIsomorphic JavaScript – future of the web
Isomorphic JavaScript – future of the webSigma Software
 
"The Story of Declarative React at Grammarly: From two-way data binding with ...
"The Story of Declarative React at Grammarly: From two-way data binding with ..."The Story of Declarative React at Grammarly: From two-way data binding with ...
"The Story of Declarative React at Grammarly: From two-way data binding with ...Fwdays
 
React vs angular
React vs angularReact vs angular
React vs angular500Tech
 
The Dark Side of Single Page Applications
The Dark Side of Single Page ApplicationsThe Dark Side of Single Page Applications
The Dark Side of Single Page ApplicationsDor Kalev
 
Intro JavaScript
Intro JavaScriptIntro JavaScript
Intro JavaScriptkoppenolski
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Previewvaluebound
 
React.js - and how it changed our thinking about UI
React.js - and how it changed our thinking about UIReact.js - and how it changed our thinking about UI
React.js - and how it changed our thinking about UIMarcin Grzywaczewski
 
Introduction to react
Introduction to reactIntroduction to react
Introduction to reactkiranabburi
 
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - DOSUG February 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - DOSUG February 2016Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - DOSUG February 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - DOSUG February 2016Matt Raible
 
Reactjs workshop
Reactjs workshop Reactjs workshop
Reactjs workshop Ahmed rebai
 
An Angular developer moving to React
An Angular developer moving to ReactAn Angular developer moving to React
An Angular developer moving to ReactSouvik Basu
 
Application Architectures in Grails
Application Architectures in GrailsApplication Architectures in Grails
Application Architectures in GrailsPeter Ledbrook
 
Angular on ASP.NET MVC 6
Angular on ASP.NET MVC 6Angular on ASP.NET MVC 6
Angular on ASP.NET MVC 6Noam Kfir
 
Client vs Server Templating: Speed up initial load for SPA with Angular as an...
Client vs Server Templating: Speed up initial load for SPA with Angular as an...Client vs Server Templating: Speed up initial load for SPA with Angular as an...
Client vs Server Templating: Speed up initial load for SPA with Angular as an...David Amend
 
One code Web, iOS, Android
One code Web, iOS, AndroidOne code Web, iOS, Android
One code Web, iOS, AndroidArtem Marchenko
 

What's hot (20)

Workshop React.js
Workshop React.jsWorkshop React.js
Workshop React.js
 
Isomorphic JavaScript – future of the web
Isomorphic JavaScript – future of the webIsomorphic JavaScript – future of the web
Isomorphic JavaScript – future of the web
 
"The Story of Declarative React at Grammarly: From two-way data binding with ...
"The Story of Declarative React at Grammarly: From two-way data binding with ..."The Story of Declarative React at Grammarly: From two-way data binding with ...
"The Story of Declarative React at Grammarly: From two-way data binding with ...
 
React vs angular
React vs angularReact vs angular
React vs angular
 
The Dark Side of Single Page Applications
The Dark Side of Single Page ApplicationsThe Dark Side of Single Page Applications
The Dark Side of Single Page Applications
 
Intro JavaScript
Intro JavaScriptIntro JavaScript
Intro JavaScript
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
 
React.js - and how it changed our thinking about UI
React.js - and how it changed our thinking about UIReact.js - and how it changed our thinking about UI
React.js - and how it changed our thinking about UI
 
Introduction to react
Introduction to reactIntroduction to react
Introduction to react
 
React js basics
React js basicsReact js basics
React js basics
 
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - DOSUG February 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - DOSUG February 2016Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - DOSUG February 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - DOSUG February 2016
 
React introduction
React introductionReact introduction
React introduction
 
Gradle Again
Gradle AgainGradle Again
Gradle Again
 
Reactjs workshop
Reactjs workshop Reactjs workshop
Reactjs workshop
 
An Angular developer moving to React
An Angular developer moving to ReactAn Angular developer moving to React
An Angular developer moving to React
 
Reactjs
Reactjs Reactjs
Reactjs
 
Application Architectures in Grails
Application Architectures in GrailsApplication Architectures in Grails
Application Architectures in Grails
 
Angular on ASP.NET MVC 6
Angular on ASP.NET MVC 6Angular on ASP.NET MVC 6
Angular on ASP.NET MVC 6
 
Client vs Server Templating: Speed up initial load for SPA with Angular as an...
Client vs Server Templating: Speed up initial load for SPA with Angular as an...Client vs Server Templating: Speed up initial load for SPA with Angular as an...
Client vs Server Templating: Speed up initial load for SPA with Angular as an...
 
One code Web, iOS, Android
One code Web, iOS, AndroidOne code Web, iOS, Android
One code Web, iOS, Android
 

Similar to MidwestJS 2014 Reconciling ReactJS as a View Layer Replacement

React.js for Rails Developers
React.js for Rails DevelopersReact.js for Rails Developers
React.js for Rails DevelopersArkency
 
Introduction to react native with redux
Introduction to react native with reduxIntroduction to react native with redux
Introduction to react native with reduxMike Melusky
 
An evening with React Native
An evening with React NativeAn evening with React Native
An evening with React NativeMike Melusky
 
Understanding Facebook's React.js
Understanding Facebook's React.jsUnderstanding Facebook's React.js
Understanding Facebook's React.jsFederico Torre
 
Isomorphic React Applications: Performance And Scalability
Isomorphic React Applications: Performance And ScalabilityIsomorphic React Applications: Performance And Scalability
Isomorphic React Applications: Performance And ScalabilityDenis Izmaylov
 
An Overview of the React Ecosystem
An Overview of the React EcosystemAn Overview of the React Ecosystem
An Overview of the React EcosystemFITC
 
Introduction to React native
Introduction to React nativeIntroduction to React native
Introduction to React nativeDhaval Barot
 
React on rails v6.1 at LA Ruby, November 2016
React on rails v6.1 at LA Ruby, November 2016React on rails v6.1 at LA Ruby, November 2016
React on rails v6.1 at LA Ruby, November 2016Justin Gordon
 
React Native and the future of web technology (Mark Wilcox) - GreeceJS #15
React Native and the future of web technology (Mark Wilcox) - GreeceJS #15React Native and the future of web technology (Mark Wilcox) - GreeceJS #15
React Native and the future of web technology (Mark Wilcox) - GreeceJS #15GreeceJS
 
Performance and Scalability Art of Isomorphic React Applications
Performance and Scalability Art of Isomorphic React ApplicationsPerformance and Scalability Art of Isomorphic React Applications
Performance and Scalability Art of Isomorphic React ApplicationsDenis Izmaylov
 
GDSC NITS Presents Kickstart into ReactJS
GDSC NITS Presents Kickstart into ReactJSGDSC NITS Presents Kickstart into ReactJS
GDSC NITS Presents Kickstart into ReactJSPratik Majumdar
 
How to Contribute to Apache Usergrid
How to Contribute to Apache UsergridHow to Contribute to Apache Usergrid
How to Contribute to Apache UsergridDavid M. Johnson
 
Дмитрий Тежельников «Разработка вэб-решений с использованием Asp.NET.Core и ...
Дмитрий Тежельников  «Разработка вэб-решений с использованием Asp.NET.Core и ...Дмитрий Тежельников  «Разработка вэб-решений с использованием Asp.NET.Core и ...
Дмитрий Тежельников «Разработка вэб-решений с использованием Asp.NET.Core и ...MskDotNet Community
 
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
 
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 comparison500Tech
 

Similar to MidwestJS 2014 Reconciling ReactJS as a View Layer Replacement (20)

React.js for Rails Developers
React.js for Rails DevelopersReact.js for Rails Developers
React.js for Rails Developers
 
Introduction to react native with redux
Introduction to react native with reduxIntroduction to react native with redux
Introduction to react native with redux
 
An evening with React Native
An evening with React NativeAn evening with React Native
An evening with React Native
 
Understanding Facebook's React.js
Understanding Facebook's React.jsUnderstanding Facebook's React.js
Understanding Facebook's React.js
 
Isomorphic React Applications: Performance And Scalability
Isomorphic React Applications: Performance And ScalabilityIsomorphic React Applications: Performance And Scalability
Isomorphic React Applications: Performance And Scalability
 
An Overview of the React Ecosystem
An Overview of the React EcosystemAn Overview of the React Ecosystem
An Overview of the React Ecosystem
 
Introduction to React native
Introduction to React nativeIntroduction to React native
Introduction to React native
 
React.js at Cortex
React.js at CortexReact.js at Cortex
React.js at Cortex
 
React Tech Salon
React Tech SalonReact Tech Salon
React Tech Salon
 
React on rails v6.1 at LA Ruby, November 2016
React on rails v6.1 at LA Ruby, November 2016React on rails v6.1 at LA Ruby, November 2016
React on rails v6.1 at LA Ruby, November 2016
 
React Native and the future of web technology (Mark Wilcox) - GreeceJS #15
React Native and the future of web technology (Mark Wilcox) - GreeceJS #15React Native and the future of web technology (Mark Wilcox) - GreeceJS #15
React Native and the future of web technology (Mark Wilcox) - GreeceJS #15
 
Performance and Scalability Art of Isomorphic React Applications
Performance and Scalability Art of Isomorphic React ApplicationsPerformance and Scalability Art of Isomorphic React Applications
Performance and Scalability Art of Isomorphic React Applications
 
GDSC NITS Presents Kickstart into ReactJS
GDSC NITS Presents Kickstart into ReactJSGDSC NITS Presents Kickstart into ReactJS
GDSC NITS Presents Kickstart into ReactJS
 
How to Contribute to Apache Usergrid
How to Contribute to Apache UsergridHow to Contribute to Apache Usergrid
How to Contribute to Apache Usergrid
 
Дмитрий Тежельников «Разработка вэб-решений с использованием Asp.NET.Core и ...
Дмитрий Тежельников  «Разработка вэб-решений с использованием Asp.NET.Core и ...Дмитрий Тежельников  «Разработка вэб-решений с использованием Asp.NET.Core и ...
Дмитрий Тежельников «Разработка вэб-решений с использованием Asp.NET.Core и ...
 
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
 
Angular or React
Angular or ReactAngular or React
Angular or React
 
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
 
Presentation1
Presentation1Presentation1
Presentation1
 
Fluxible
FluxibleFluxible
Fluxible
 

Recently uploaded

Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialJoão Esperancinha
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Nikki Chapple
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxAna-Maria Mihalceanu
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Jeffrey Haguewood
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Français Patch Tuesday - Avril
Français Patch Tuesday - AvrilFrançais Patch Tuesday - Avril
Français Patch Tuesday - AvrilIvanti
 
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
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 

Recently uploaded (20)

Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorial
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance Toolbox
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Français Patch Tuesday - Avril
Français Patch Tuesday - AvrilFrançais Patch Tuesday - Avril
Français Patch Tuesday - Avril
 
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...
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 

MidwestJS 2014 Reconciling ReactJS as a View Layer Replacement

  • 1. Reconciling React as a View Layer Replacement Zach Lendon @zachlendon #reactjs #midwestjs #reactjsisawesome https://github.com/zachlendon/midwestjs2014
  • 2. Traditional JS MV* “issues” •“State” •Performance •Complexity •Predictability •Testability • Isomorphic Javascript • The right simple :: powerful ratio • The right configurable :: opinionated ratio • Pluggable modular architecture • Performant • SEO Top keys to future “web” MV* framework success “State” of the JS MV*
  • 3. Meet React •A Javascript Library for Creating User Interfaces •https://github.com/facebook/react •Open Sourced and Battle-tested by Facebook and Instagram •Browser support to IE8
  • 4. “React is not a full MVC framework, and this is actually one of its strengths. Many who adopt React choose to do so alongside their favorite MVC framework, like Backbone. React has no opinions about routing or syncing data, so you can easily use your favorite tools to handle those aspects of your frontend application. You'll often see React used to manage specific parts of an application's UI and not others. React really shines, however, when you fully embrace its strategies and make it the core of your application's interface.” @bkonkle: http://lincolnloop.com/blog/architecting-your-app-react-part-1/
  • 5. Why React? • “State” is what makes building UIs hard • “Data Changing over time is the Root of All Evil”
  • 6. React Solution Use composable React components that effectively re-render themselves on each state mutation
  • 8. Virtual DOM •In-memory representation of the DOM and events system •Even HTML5 events in IE8
  • 9. Advantages of Virtual DOM •Interacting with DOM -> Slow, •with Javascript In-Memory Objects -> fast •60 fps fast •Faster parsing •Faster Validation •Since no real browser, can easily render on server or client •Easier To Test
  • 10. Fallout Advantages of Virtual DOM include •Autobinding •Event Delegation
  • 12. React Components React Components translate raw data into rich HTML The Ultimate State Machine
  • 14. Render: “pure” Javascript function http://jsfiddle.net/zlendon/9xyn3/
  • 15. Render: “pure” Coffeescript function http://jsfiddle.net/zlendon/32xj5/
  • 16. Render: Better “pure” Coffeescript function http://jsfiddle.net/zlendon/32xj5/1/
  • 17. Render: “JSX” Javascript function http://jsfiddle.net/zH5YG/
  • 18. JSX “Desugared” to native Javascript
  • 19. Rules of Render •Return a single child component •Native DOM component •Composite Component •Return predictable result each time invoked •Does not touch the DOM (read or write) or interact with the browser (i.e., setTimeout) !
  • 20. Rules of Server Side Render ! ! ! ! •renderComponentToString on server •render on client, to same node, preserves server-rendered markup and adds event handlers •http://www.princeton.edu/~crmarsh/react-ssr/ (Charlie Marsh) •https://github.com/andreypopp/react-async •https://github.com/karlmikko/bleeding-edge- sample-app/blob/react-router/server/render/ render.js (soon to be in React-Router) tl&dr;
  • 21. React Components: Input •Props: immutable data specific to an instance of a component •Like params into a function •State: Private mutable attribute. Change within which trigger scheduling of a component re-render
  • 22. Both Props and State • Are plain JS objects • Changes trigger a render update • Are deterministic. If your Component generates different outputs for the same combination of props and state then you're doing something wrong. https://github.com/uberVU/react-guide/blob/master/props-vs-state.md#readme
  • 23. Rules of State •Belong to only one component •Within that component, modified 2 ways •getInitialState •setState •Render returns same result each time invoked with same state •Do not use computed data or duplicate prop data as state •Avoid using state when possible •Do not change state of children components
  • 24. Rules of Props •Passed from the parent •Immutable •Often pass callback functions through them !
  • 25. Component Lifecycle Mounting • componentWillMount() • componentDidMount() ! Updating • componentWillReceiveProps(object nextProps) • boolean shouldComponentUpdate(object nextProps, object nextState) • componentWillUpdate(object nextProps, object nextState) • componentDidUpdate(object prevProps, object prevState) ! Unmounting • componentWillUnmount()
  • 26. Mixins •Cross cutting concerns •Examples: •ReactScriptLoader: https://github.com/yariv/ReactScriptLoader •ReactIntlMixin: https://github.com/yahoo/react-intl •Backbone.React.Component.mixin: https://github.com/ magalhas/backbone-react-component
  • 27. Scaling React ! ! ! ! Action Controller Model View Conference MVC • Modified from Flux into by Jing Chen at F8, 2014
  • 28. Scaling with React ! ! ! ! Action Controller Model View Model Model Model Model Model View View View View View View Real World MVC
  • 29. Scaling with React ! ! ! ! Action Dispatcher Store View Action Flux
  • 30. Starting a New App: React •Lots of Great “Full-Stack” Starter Kit Options - Many Listed: https://github.com/facebook/react/wiki/Complementary-Tools
  • 31. New Project w/ Routing •React Boilerplate: https://github.com/rackt/react-boilerplate •Uses: •React-router (prev. react-nested-router) •Translation of Ember Router API to React •Webpack •pushstate-serv
  • 32. New Project w/o Routing •https://github.com/newtriks/generator-react-webpack •Yeoman Generator •Uses: •Webpack •Grunt •Karma
  • 33. New Project w/ Routing & Server-side Rendering: •React Quickstart: •https://github.com/newtriks/generator-react-webpack •Uses: •react-router-component •react-async •express •browserify •npm
  • 34. New Project: Midwest JS Demo •React Boilerplate •Plus: •Express (3) •Bootstrap 3
  • 36. Adding React To Existing Project “We don’t need to switch to React everywhere, all at once. It’s not a framework that imposes anything on the application structure. [...] Easy, iterative adoption is definitely something in React’s favor for us.” ! -Adobe Brackets Team
  • 37. Backbone Views •Nested Backbone.View’s are difficult to maintain •Every collection change re-renders all views
  • 39. Integration with Backbone Models and Collections •Trigger React re-render on Backbone model “change” events
  • 40. Mixins! Maybe Lost shouldComponentUpdate hooks TODO MVC: React + Backbone
  • 46. Angular Directives Wrapping React •ngReact •ngReactGrid
  • 48. Integration Lessons •You can integrate React with other frameworks •Backbone integration works better than many options since re- rendering on model state change is the typical Backbone approach •Angular will work best from directives but is a bit of a force fit •Best approach to let React own the DOM element being rendered into
  • 49. (Beyond the Obvious) Additional Resources (1/2) •Great Collection of Community links:
 https://github.com/mindreframer/reactjs-stuff •Developing User Interfaces with React: http://youtu.be/ 1OeXsL5mr4g?list=PLuE9Gq9Mxr5kCvVa7tcwW1S2-FEym5fbt (intro + good performance demo) •Good Flux intro by Ryan Florence: http://vimeo.com/ 102953099 •Thorough and infamous Angular/ReactJS performance/ integration post: http://www.williambrownstreet.net/blog/ 2014/04/faster-angularjs-rendering-angularjs-and-reactjs/ •Performance Tools: http://facebook.github.io/react/docs/ perf.html !
  • 50. (Beyond the Obvious) Additional Resources (2/2) ! •Webpack Howto: https://github.com/petehunt/webpack- howto •Webpack Hot Module Replacement: https://github.com/ webpack/docs/wiki/hot-module-replacement-with-webpack •Om: https://github.com/swannodette/om •Jest: http://facebook.github.io/jest/
  • 51. Thank You Questions? Zach Lendon @zachlendon #reactjs #midwestjs https://github.com/zachlendon #reactjs on freenode