SlideShare a Scribd company logo
1 of 29
ReactJS
Re-rendering pages in the age of the mutable DOM
React re-renders entire component
whenever data changes
• 80s/90s — user input caused re-render of entire
web page. Why is this best?
• Immutable vs Mutable — mutations can cause
complexity to a point where an app is no longer
maintainable
“React components are idempotent functions.
They describe your UI at any point in time, just
like a server-rendered application.”
What does React do about
Mutable vs Immutable state?
• React isolates mutable state as much as possible.
• Re-rendering on every change makes things simple -
data is guaranteed to be up-to-date
• This is w/out magical data-binding, w/out model dirty
checking, and w/out explicit DOM operations
• Extra note: Why is dirty checking bad? It’s expensive
and as your application grows in complexity, it can
cause your code to get out of hand quickly
Everything is
declarative!
But how can you re-render every
time data changes?
Isn’t this too expensive?
… Enter the Virtual
DOM
What is the v-DOM and how
does it work?
• The v-DOM is a virtualized representation of the
DOM at different points in time (before and after
state change)
• This virtualization is made up of lightweight
JavaScript objects that represent the DOM tree.
As such - it is inexpensive to store in memory and
allows the diffing algorithm to execute in
milliseconds
On every update…
• React builds a new v-DOM subtree
• diffs it with the old one
• computes the minimal set of DOM mutations and
puts them in queue
• and batch executes all updates
It does this in
milliseconds
• React is fast because it computes minimal DOM
operations — the DOM is slow, JavaScript is
actually very, very fast
• React batches read/writes for optimal
performance automatically. It does this through
use of the v-DOM which is inherently faster than
the actual DOM.
Some other points of interest
• Automatic top-level event delegation with cross-
browser HTML5 events
• React also has a virtual event system in addition
to the v-DOM system
What else matters?
Web crawlers!
• One of the big drawbacks to single-page
applications that rely on user input is that web
crawlers can’t index them the same way they can
static pages
• React can generate a static HTML page and send
it down to the client, and then when render
component is called, it looks at the DOM - checks
with what was rendered on server... fast initial page
load experience and Google web-bots can crawl
What does that mean…
the long paragraph there?
“React can generate a static HTML page and
send it down to the client, and then when render
component is called, it looks at the DOM -
checks with what was rendered on server... fast
initial page load experience and Google web-
bots can crawl.”
What this means…
• You can generate a static html page and send it
down — something that can be crawled and
indexed
• Then, when JS boots up, it will replace DOM
elements as needed to boot up the UI
• Resulting in an indexable page that is fully built
on JavaScript
Let’s pause for a minute to note
some key takeaways so far
• Build components, not templates
• Re-render, don’t mutate
• V-DOM is simple and fast
So where does Flux come
in? … also, Relay is
coming soon
As you build apps on React,
you will remove models
• In most MV* JS frameworks, model is just a JS object
that allows you to know when something changes —
when data changes (enter two-way data-binding)
• Example:
• You have a model with Title and Subtitle. When something changes you manually
wire up the views to have a node change when the Title changes.
• You change the inner text on some node when the Title changes
• You have to wire this up yourself completely — in Backbone, you have to
wire both ways. In some other frameworks, you only have to wire one way,
but this is still a lot of code.
How is React different
in this example?
With React…
• You trigger a state change.
• Re-render happens.
• Diff happens in background automatically.
• View updates without any flashing in the DOM and
it happens very, very quickly.
• This shortens the amount of code you have to
write.
React can be most powerful
without models
• This does not mean you don’t have data structure
• You use the Flux design pattern (or coming soon,
the Relay framework)
• This is where stores come in…
What is a Store?
Everything’s in Flux
• Centralized stores represent UI components
• The store is your source of truth for the data of
your application
• When you ask a store for data, if it doesn’t have
it, it fetches it and invokes your callback after it
gets it
This centralizes validation
and update logic in one
place.
Think about it.. mutation
all over the place is not
ideal.
More on Relay when it
becomes available to the
public as open-source

More Related Content

What's hot

Introduction to react
Introduction to reactIntroduction to react
Introduction to reactkiranabburi
 
Understanding Facebook's React.js
Understanding Facebook's React.jsUnderstanding Facebook's React.js
Understanding Facebook's React.jsFederico Torre
 
ReactJS.NET - Fast and Scalable Single Page Applications
ReactJS.NET - Fast and Scalable Single Page ApplicationsReactJS.NET - Fast and Scalable Single Page Applications
ReactJS.NET - Fast and Scalable Single Page ApplicationsRick Beerendonk
 
Introduction to React, Flux, and Isomorphic Apps
Introduction to React, Flux, and Isomorphic AppsIntroduction to React, Flux, and Isomorphic Apps
Introduction to React, Flux, and Isomorphic AppsFederico Torre
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVC Introduction to ASP.NET MVC
Introduction to ASP.NET MVC Joe Wilson
 
BP101: A Modernized Workflow w/ Domino/XPages
BP101: A Modernized Workflow w/ Domino/XPagesBP101: A Modernized Workflow w/ Domino/XPages
BP101: A Modernized Workflow w/ Domino/XPagesedm00se
 
Introduce Flux & react in practices (KKBOX)
Introduce Flux & react in practices (KKBOX)Introduce Flux & react in practices (KKBOX)
Introduce Flux & react in practices (KKBOX)Hsuan Fu Lien
 
JavaScript innovaties: ECMAScript 6 & 7
JavaScript innovaties: ECMAScript 6 & 7JavaScript innovaties: ECMAScript 6 & 7
JavaScript innovaties: ECMAScript 6 & 7Rick Beerendonk
 
Akka - Developing SEDA Based Applications
Akka - Developing SEDA Based ApplicationsAkka - Developing SEDA Based Applications
Akka - Developing SEDA Based ApplicationsBenjamin Darfler
 
Intro to Flux - ReactJS Warsaw #1
Intro to Flux - ReactJS Warsaw #1Intro to Flux - ReactJS Warsaw #1
Intro to Flux - ReactJS Warsaw #1Damian Legawiec
 
React server side rendering performance
React server side rendering performanceReact server side rendering performance
React server side rendering performanceNick Dreckshage
 
A 20 minute introduction to AngularJS for XPage developers
A 20 minute introduction to AngularJS for XPage developersA 20 minute introduction to AngularJS for XPage developers
A 20 minute introduction to AngularJS for XPage developersMark Leusink
 
ASP.NET MVC From The Ground Up
ASP.NET MVC From The Ground UpASP.NET MVC From The Ground Up
ASP.NET MVC From The Ground UpKevin Griffin
 

What's hot (20)

Evolution of java script libraries
Evolution of java script librariesEvolution of java script libraries
Evolution of java script libraries
 
Introduction to react
Introduction to reactIntroduction to react
Introduction to react
 
Understanding Facebook's React.js
Understanding Facebook's React.jsUnderstanding Facebook's React.js
Understanding Facebook's React.js
 
Flux architecture
Flux architectureFlux architecture
Flux architecture
 
ReactJS.NET - Fast and Scalable Single Page Applications
ReactJS.NET - Fast and Scalable Single Page ApplicationsReactJS.NET - Fast and Scalable Single Page Applications
ReactJS.NET - Fast and Scalable Single Page Applications
 
Introduction to React, Flux, and Isomorphic Apps
Introduction to React, Flux, and Isomorphic AppsIntroduction to React, Flux, and Isomorphic Apps
Introduction to React, Flux, and Isomorphic Apps
 
About Flux
About FluxAbout Flux
About Flux
 
React in 2018
React in 2018React in 2018
React in 2018
 
Introduction to-react
Introduction to-reactIntroduction to-react
Introduction to-react
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVC Introduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
BP101: A Modernized Workflow w/ Domino/XPages
BP101: A Modernized Workflow w/ Domino/XPagesBP101: A Modernized Workflow w/ Domino/XPages
BP101: A Modernized Workflow w/ Domino/XPages
 
Introduce Flux & react in practices (KKBOX)
Introduce Flux & react in practices (KKBOX)Introduce Flux & react in practices (KKBOX)
Introduce Flux & react in practices (KKBOX)
 
JavaScript innovaties: ECMAScript 6 & 7
JavaScript innovaties: ECMAScript 6 & 7JavaScript innovaties: ECMAScript 6 & 7
JavaScript innovaties: ECMAScript 6 & 7
 
Single Page Application
Single Page ApplicationSingle Page Application
Single Page Application
 
Akka - Developing SEDA Based Applications
Akka - Developing SEDA Based ApplicationsAkka - Developing SEDA Based Applications
Akka - Developing SEDA Based Applications
 
Intro to Flux - ReactJS Warsaw #1
Intro to Flux - ReactJS Warsaw #1Intro to Flux - ReactJS Warsaw #1
Intro to Flux - ReactJS Warsaw #1
 
React server side rendering performance
React server side rendering performanceReact server side rendering performance
React server side rendering performance
 
A 20 minute introduction to AngularJS for XPage developers
A 20 minute introduction to AngularJS for XPage developersA 20 minute introduction to AngularJS for XPage developers
A 20 minute introduction to AngularJS for XPage developers
 
Async js
Async jsAsync js
Async js
 
ASP.NET MVC From The Ground Up
ASP.NET MVC From The Ground UpASP.NET MVC From The Ground Up
ASP.NET MVC From The Ground Up
 

Similar to ReactJS - Re-rendering pages in the age of the mutable DOM

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
 
Advanced web application architecture - Talk
Advanced web application architecture - TalkAdvanced web application architecture - Talk
Advanced web application architecture - TalkMatthias Noback
 
Meteor Revolution: From DDP to Blaze Reactive Rendering
Meteor Revolution: From DDP to Blaze Reactive Rendering Meteor Revolution: From DDP to Blaze Reactive Rendering
Meteor Revolution: From DDP to Blaze Reactive Rendering Massimo Sgrelli
 
Learning React - I
Learning React - ILearning React - I
Learning React - IMitch Chen
 
Introduction to react native with redux
Introduction to react native with reduxIntroduction to react native with redux
Introduction to react native with reduxMike Melusky
 
Intro to SPA using JavaScript & ASP.NET
Intro to SPA using JavaScript & ASP.NETIntro to SPA using JavaScript & ASP.NET
Intro to SPA using JavaScript & ASP.NETAlan Hecht
 
What is virtual dom in react js
What is virtual dom in react jsWhat is virtual dom in react js
What is virtual dom in react jsBOSC Tech Labs
 
Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!Jeremy Likness
 
Advanced web application architecture Way2Web
Advanced web application architecture Way2WebAdvanced web application architecture Way2Web
Advanced web application architecture Way2WebMatthias Noback
 
Robust web apps with React.js
Robust web apps with React.jsRobust web apps with React.js
Robust web apps with React.jsMax Klymyshyn
 
WebMate: A Tool for Testing Web 2.0 Applications
WebMate: A Tool for Testing Web 2.0 ApplicationsWebMate: A Tool for Testing Web 2.0 Applications
WebMate: A Tool for Testing Web 2.0 ApplicationsAnwarrChaudary
 
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
 
Project First presentation about introduction to technologies to be used
Project First presentation about introduction to technologies to be usedProject First presentation about introduction to technologies to be used
Project First presentation about introduction to technologies to be usedarya krazydude
 
Welcome to React & Flux !
Welcome to React & Flux !Welcome to React & Flux !
Welcome to React & Flux !Ritesh Kumar
 

Similar to ReactJS - Re-rendering pages in the age of the mutable DOM (20)

React js
React jsReact js
React js
 
React Tech Salon
React Tech SalonReact Tech Salon
React Tech Salon
 
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
 
Advanced web application architecture - Talk
Advanced web application architecture - TalkAdvanced web application architecture - Talk
Advanced web application architecture - Talk
 
Benefits of developing single page web applications using angular js
Benefits of developing single page web applications using angular jsBenefits of developing single page web applications using angular js
Benefits of developing single page web applications using angular js
 
Meteor Revolution: From DDP to Blaze Reactive Rendering
Meteor Revolution: From DDP to Blaze Reactive Rendering Meteor Revolution: From DDP to Blaze Reactive Rendering
Meteor Revolution: From DDP to Blaze Reactive Rendering
 
Learning React - I
Learning React - ILearning React - I
Learning React - I
 
Introduction to react native with redux
Introduction to react native with reduxIntroduction to react native with redux
Introduction to react native with redux
 
React.js at Cortex
React.js at CortexReact.js at Cortex
React.js at Cortex
 
Intro to SPA using JavaScript & ASP.NET
Intro to SPA using JavaScript & ASP.NETIntro to SPA using JavaScript & ASP.NET
Intro to SPA using JavaScript & ASP.NET
 
Meteor + React
Meteor + ReactMeteor + React
Meteor + React
 
What is virtual dom in react js
What is virtual dom in react jsWhat is virtual dom in react js
What is virtual dom in react js
 
Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!
 
Advanced web application architecture Way2Web
Advanced web application architecture Way2WebAdvanced web application architecture Way2Web
Advanced web application architecture Way2Web
 
React DOM/Virtual DOM
React DOM/Virtual DOMReact DOM/Virtual DOM
React DOM/Virtual DOM
 
Robust web apps with React.js
Robust web apps with React.jsRobust web apps with React.js
Robust web apps with React.js
 
WebMate: A Tool for Testing Web 2.0 Applications
WebMate: A Tool for Testing Web 2.0 ApplicationsWebMate: A Tool for Testing Web 2.0 Applications
WebMate: A Tool for Testing Web 2.0 Applications
 
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)
 
Project First presentation about introduction to technologies to be used
Project First presentation about introduction to technologies to be usedProject First presentation about introduction to technologies to be used
Project First presentation about introduction to technologies to be used
 
Welcome to React & Flux !
Welcome to React & Flux !Welcome to React & Flux !
Welcome to React & Flux !
 

Recently uploaded

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
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
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
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
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
🐬 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
 
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
 
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
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
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
 

Recently uploaded (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
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...
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
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 ...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
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
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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
 

ReactJS - Re-rendering pages in the age of the mutable DOM

  • 1. ReactJS Re-rendering pages in the age of the mutable DOM
  • 2. React re-renders entire component whenever data changes • 80s/90s — user input caused re-render of entire web page. Why is this best? • Immutable vs Mutable — mutations can cause complexity to a point where an app is no longer maintainable
  • 3. “React components are idempotent functions. They describe your UI at any point in time, just like a server-rendered application.”
  • 4. What does React do about Mutable vs Immutable state? • React isolates mutable state as much as possible. • Re-rendering on every change makes things simple - data is guaranteed to be up-to-date • This is w/out magical data-binding, w/out model dirty checking, and w/out explicit DOM operations • Extra note: Why is dirty checking bad? It’s expensive and as your application grows in complexity, it can cause your code to get out of hand quickly
  • 6. But how can you re-render every time data changes? Isn’t this too expensive?
  • 7. … Enter the Virtual DOM
  • 8. What is the v-DOM and how does it work? • The v-DOM is a virtualized representation of the DOM at different points in time (before and after state change) • This virtualization is made up of lightweight JavaScript objects that represent the DOM tree. As such - it is inexpensive to store in memory and allows the diffing algorithm to execute in milliseconds
  • 9. On every update… • React builds a new v-DOM subtree • diffs it with the old one • computes the minimal set of DOM mutations and puts them in queue • and batch executes all updates
  • 10. It does this in milliseconds
  • 11. • React is fast because it computes minimal DOM operations — the DOM is slow, JavaScript is actually very, very fast • React batches read/writes for optimal performance automatically. It does this through use of the v-DOM which is inherently faster than the actual DOM.
  • 12. Some other points of interest • Automatic top-level event delegation with cross- browser HTML5 events • React also has a virtual event system in addition to the v-DOM system
  • 14. Web crawlers! • One of the big drawbacks to single-page applications that rely on user input is that web crawlers can’t index them the same way they can static pages • React can generate a static HTML page and send it down to the client, and then when render component is called, it looks at the DOM - checks with what was rendered on server... fast initial page load experience and Google web-bots can crawl
  • 15. What does that mean… the long paragraph there?
  • 16. “React can generate a static HTML page and send it down to the client, and then when render component is called, it looks at the DOM - checks with what was rendered on server... fast initial page load experience and Google web- bots can crawl.”
  • 17. What this means… • You can generate a static html page and send it down — something that can be crawled and indexed • Then, when JS boots up, it will replace DOM elements as needed to boot up the UI • Resulting in an indexable page that is fully built on JavaScript
  • 18. Let’s pause for a minute to note some key takeaways so far • Build components, not templates • Re-render, don’t mutate • V-DOM is simple and fast
  • 19. So where does Flux come in? … also, Relay is coming soon
  • 20. As you build apps on React, you will remove models • In most MV* JS frameworks, model is just a JS object that allows you to know when something changes — when data changes (enter two-way data-binding) • Example: • You have a model with Title and Subtitle. When something changes you manually wire up the views to have a node change when the Title changes. • You change the inner text on some node when the Title changes • You have to wire this up yourself completely — in Backbone, you have to wire both ways. In some other frameworks, you only have to wire one way, but this is still a lot of code.
  • 21. How is React different in this example?
  • 22. With React… • You trigger a state change. • Re-render happens. • Diff happens in background automatically. • View updates without any flashing in the DOM and it happens very, very quickly. • This shortens the amount of code you have to write.
  • 23. React can be most powerful without models • This does not mean you don’t have data structure • You use the Flux design pattern (or coming soon, the Relay framework) • This is where stores come in…
  • 24. What is a Store?
  • 25. Everything’s in Flux • Centralized stores represent UI components • The store is your source of truth for the data of your application • When you ask a store for data, if it doesn’t have it, it fetches it and invokes your callback after it gets it
  • 26. This centralizes validation and update logic in one place.
  • 27. Think about it.. mutation all over the place is not ideal.
  • 28.
  • 29. More on Relay when it becomes available to the public as open-source