SlideShare a Scribd company logo
FUNCTIONAL WEB 
DEVELOPMENT - AN 
INTRODUCTION TO React.js
HELLO, MY NAME IS Bertrand 
KARERANGABO. 
@BERTRANDK
I WORK AT RANGLE.IO
Moar functional! 
— Nick Van Weerdenburg
typeof NaN === 'number' //=> true
WHAT PROBLEM ARE WE 
TALKING ABOUT TODAY?
Most software today is very 
much like an Egyptian 
pyramid with millions of 
bricks piled on top of each 
other, with no structural 
integrity, but just done by 
brute force and thousands 
of slaves. 
— Alan Kay
THE PROBLEM HOW CAN WE BUILD LARGE APPLICATIONS 
WITH DATA THAT CHANGES OVER TIME?
Functional Web Development
▸ A (very) short history of web development 
▸ OOP in the wild 
▸ Functional design 
▸ React.js 
▸ Immutable (data stuctures) 
▸ The server (SEO & performance) 
▸ The end
1979 · MODEL-VIEW-CONTROLLER IS BORN 
It was fist articulated by Trygve Reenskaug, Adele Goldberg and others 
at Xeroc PARC. 
MVC was conceived as a general solution to the problem of users 
controlling a large and complex data set.
MVC AND IT'S LATER VARIANTS HAVE ALL 
INHERITED FROM THE INITIAL OOP-BASED 
IMPLEMENTATION.
1990 · THE FIRST WEB 
BROWSER 
It was invented by Tim Berners-Lee and was 
initially called WorldWideWeb. 
▸ It was written in Objective-C. 
▸ It introduced an Internet-based document 
system called HyperText Markup Language. 
▸ The layout engine was a subclass of 
NeXTSTEP's Text class. 
▸ The document is static – if data changes, you 
must refresh!
1995 · THE FIRST DOM 
The Level 0 DOM was created by Netscape for Netscape Navigator 2.0. 
The idea was to give web developers a means by which to allow users to 
interact with a site. 
Given that an HTML document can be represented as a tree, the DOM API 
allows for developers to interact and manipulate the tree's nodes.
1995 · THE FIRST 
JAVASCRIPT
▸ A (very) short history of web development 
▸ OOP in the wild 
▸ Functional design 
▸ React.js 
▸ Immutable (data stuctures) 
▸ The server (SEO & performance) 
▸ The end
A SHOPPING CART
A SHOPPING CART - OOP DATA
A SHOPPING CART - OOP DATA & METHODS
Local state that changes over time is 
the root of all evil.
A BASIC COMPUTER IN 1995 
Ram: 8MB 
HDD: 1GB 
CPU: 33MHz
LET'S NOT WRITE 
SOFTWARE LIKE 
IT'S 1995.
WE NEED A 
BETTER 
ABSTRACTION
▸ A (very) short history of web development 
▸ OOP in the wild 
▸ Functional design 
▸ React.js 
▸ Immutable (data stuctures) 
▸ The server (SEO & performance) 
▸ The end
A SHOPPING CART - FP DATA
A SHOPPING CART - FP DATA
A SOLUTION 
REACT.JS + IMMUTABLE-JS
▸ A (very) short history of web development 
▸ OOP in the wild 
▸ Functional design 
▸ React.js 
▸ Immutable (data stuctures) 
▸ The server (SEO & performance) 
▸ The end
REACT.JS A JAVASCRIPT LIBRARY FOR BUILDING 
COMPOSABLE USER INTERFACES
REACT.JS VIRTUAL DOM 
The full DOM API in JavaScript. 
When rendering, it uses a diff implementation for ultra-high 
performance. 
f(newDOM, oldDOM) = Δ
REACT.JS COMPONENT 
var App = React.createClass({ 
render: function() { 
return React.DOM.h1(null, 'Hello'); 
}; 
});
REACT.JS RENDER 
var App = React.createClass({ 
render: function() { 
return React.DOM.h1(null, 'Hello'); 
}; 
}); 
React.renderComponent(App(null), document.body);
REACT.JS PROPS 
var french = 'Allo'; 
var App = React.createClass({ 
render: function() { 
return React.DOM.h1(null, this.props.salutation ); 
}; 
}); 
React.renderComponent(App({ salutation: french }), document.body);
REACT.JS DOM PROPERTIES 
var french = 'Allo'; 
var App = React.createClass({ 
render: function() { 
return React.DOM.h1({ className: 'title' }, this.props.salutation ); 
}; 
}); 
React.renderComponent(App({ salutation: french }), document.body);
REACT.JS EVENTS 
var french = 'Allo'; 
function scream() { 
alert("I've been clicked!"); 
} 
var App = React.createClass({ 
render: function() { 
return React.DOM.h1({ className: 'title', 
onClick: this.props.clickHandler }, 
this.props.salutation ); 
}; 
}); 
React.renderComponent(App({ salutation: french, clickHandler: scream }), document.body);
REACT.JS STATE* 
var french = 'Allo'; 
var App = React.createClass({ 
getInitialState: function() { 
return { name: 'Unknown' }; 
}, 
componentDidMount: function() { 
$.ajax({ 
url: '/me', 
dataType: 'json', 
success: function(data) { 
this.setState({ name: data }); 
}.bind(this); 
}); 
}, 
render: function() { 
var fullSalutation = this.props.salutation + ', ' + this.state.name; 
return React.DOM.h1(null, fullSalutation); 
}; 
}); 
React.renderComponent(App({ salutation: french }), document.body);
REACT.JS COMPONENT SPECIFICATION 
- render 
- getInitialState 
- getDefaultProps 
- propTypes 
- mixins 
- statics 
- displayName
REACT.JS COMPONENT LIFECYCLE 
Mounting: 
- componentWillMount 
- componentDidMount 
Updating: 
- componentWillReceiveProps 
- shouldComponentUpdate 
- componentWillUpdate 
- componentDidUpdate 
Unmounting: 
- componentWillUnmount
REACT.JS SHOPPING CART
▸ A (very) short history of web development 
▸ OOP in the wild 
▸ Functional design 
▸ React.js 
▸ Immutable (data stuctures) 
▸ The server (SEO & performance) 
▸ The end
IMMUTABLE IMMUTABLE AND PERSISTENT DATA 
STRUCTURES + SUPPORTING APIS
IMMUTABLE MAPS 
var map1 = Immutable.Map({ a: 1, b: 2, c: 3 }); 
map2 = map.set('b', 20); // note the assignment 
map2.get('b'); // 20 
map1.get('b'); // 2
IMMUTABLE VECTOR 
var vect1 = Immutable.Vector(1, 2); 
var vect2 = vect1.push(3, 4, 5); 
var vect3 = vect2.unshift(0); 
var vect4 = vect1.concat(vect2, vect3); 
assert(vect1.length === 2); 
assert(vect2.length === 5); 
assert(vect3.length === 6); 
assert(vect4.length === 13); 
assert(vect4.get(0) === 1);
IMMUTABLE EQUALITY 
var map1 = Immutable.Map({a:1, b:1, c:1}); 
var map2 = Immutable.Map({a:1, b:1, c:1}); 
assert(map1 !== map2); 
assert(Immutable.is(map1, map2) === true);
IMMUTABLE INTEROP 
var deep = Immutable.Map({a:1, b:2, c:Immutable.Vector(3,4,5)}); 
deep.toObject() // { a: 1, b: 2, c: Vector [ 3, 4, 5 ] } 
deep.toArray() // [ 1, 2, Vector [ 3, 4, 5 ] ] 
deep.toJS() // { a: 1, b: 2, c: [ 3, 4, 5 ] } 
JSON.stringify(deep) // '{"a":1,"b":2,"c":[3,4,5]}'
IMMUTABLE CURSORS 
var appData = Immutable.fromJS({ a: { b: { c: 1 } } }); 
var userData = appData.cursor(['a', 'b', 'c'], function(newData) { 
appData = newData; 
}); 
// ... elsewhere ... 
userData.deref(); // 1 
userData = userData.update(function(x) { return x + 1 }); 
userData.deref(); // 2 
// ... back to data ... 
appData.getIn(['a', 'b', 'c']); // 2
IMMUTABLE SHOPPING CART
▸ A (very) short history of web development 
▸ OOP in the wild 
▸ Functional design 
▸ React.js 
▸ Immutable (data stuctures) 
▸ The server (SEO & performance) 
▸ The end
SERVER-SIDE RENDERING 
var url = require('url') 
function(req, res, next) { 
// get the application path/stage 
var path = url.parse(req.url).pathname; 
// get a React.js component 
var app = App({path: path}); 
// render component into string instead of DOM 
var markup = React.renderComponentToString(app); 
// return full html and let client-side takeover 
res.send(markup); 
}
▸ A (very) short history of web development 
▸ OOP in the wild 
▸ Functional design 
▸ React.js 
▸ Immutable (data stuctures) 
▸ The server (SEO & performance) 
▸ The end
WE NOW HAVE SOLID MODEL 
FOR DATA THAT CHANGES 
OVER TIME.
MIND THE PUNCHLINE 
It's not important that the chicken crossed the road or even how it did 
it. 
What's important is why it crossed the road.
Thank you!

More Related Content

ZIP
Javascript Everywhere From Nose To Tail
PDF
Redux. From twitter hype to production
PDF
«От экспериментов с инфраструктурой до внедрения в продакшен»​
PDF
A real-world Relay application in production - Stefano Masini - Codemotion Am...
PDF
Benchx: An XQuery benchmarking web application
PPT
Headless drupal + react js Oleksandr Linyvyi
PDF
"Service Worker: Let Your Web App Feel Like a Native "
PDF
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
Javascript Everywhere From Nose To Tail
Redux. From twitter hype to production
«От экспериментов с инфраструктурой до внедрения в продакшен»​
A real-world Relay application in production - Stefano Masini - Codemotion Am...
Benchx: An XQuery benchmarking web application
Headless drupal + react js Oleksandr Linyvyi
"Service Worker: Let Your Web App Feel Like a Native "
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017

What's hot (18)

PDF
Devoxx uk 2014 High performance in-memory Java with open source
PPT
Mobile webapplication development
PDF
Docker in Action
ODP
Alexander Dymo - RailsConf 2014 - Improve performance: Optimize Memory and Up...
PDF
MLBlock
PDF
GCPUG meetup 201610 - Dataflow Introduction
PDF
Sprint 39 review
PDF
PostgreSQL v9.4features
PDF
Full Stack Toronto - the 3R Stack
PDF
Monitoring at a SAAS Startup: Tradeoffs and Tools
PPTX
The hitchhiker's guide to the Webpack - Sara Vieira - Codemotion Amsterdam 2017
PPTX
JavaScript Task Runners - Gulp & Grunt
PDF
Reusing your frontend JS on the server with V8/Rhino
PDF
MongoDB .local Paris 2020: Adéo @MongoDB : MongoDB Atlas & Leroy Merlin : et ...
PPTX
Building multi lingual and empatic bots - Sander van den Hoven - Codemotion A...
PDF
React for Beginners
PDF
用 OPENRNDR 將 Chatbot 訊息視覺化
PDF
Sprint 36 review
Devoxx uk 2014 High performance in-memory Java with open source
Mobile webapplication development
Docker in Action
Alexander Dymo - RailsConf 2014 - Improve performance: Optimize Memory and Up...
MLBlock
GCPUG meetup 201610 - Dataflow Introduction
Sprint 39 review
PostgreSQL v9.4features
Full Stack Toronto - the 3R Stack
Monitoring at a SAAS Startup: Tradeoffs and Tools
The hitchhiker's guide to the Webpack - Sara Vieira - Codemotion Amsterdam 2017
JavaScript Task Runners - Gulp & Grunt
Reusing your frontend JS on the server with V8/Rhino
MongoDB .local Paris 2020: Adéo @MongoDB : MongoDB Atlas & Leroy Merlin : et ...
Building multi lingual and empatic bots - Sander van den Hoven - Codemotion A...
React for Beginners
用 OPENRNDR 將 Chatbot 訊息視覺化
Sprint 36 review
Ad

Viewers also liked (20)

PDF
Making Mixed Reality Living Spaces
PDF
A Journey with React
PDF
From Box to Bots in Minutes
PDF
Building Tools for the Next Web
PPTX
21st Century Crystal Ball
PDF
I HATE YOUR GAME with Bob Heubel
PDF
Just Make Stuff!
PDF
Getting to Know Grunt By Writing Your Own Plugin
PDF
Here Be Dragons – Advanced JavaScript Debugging
PDF
The Browser Is Dead, Long Live The Web!
PDF
Components are the Future of the Web: It’s Going To Be Okay
PDF
I Heard React Was Good
PPTX
Managing Responsive Design Projects
PDF
Squishy pixels
PDF
How We Used To, How We Will
PDF
The Life of <p>
PDF
Reinvent Your Creative Process with Collaborative Hackathons
PPTX
Your UX is not my UX
PDF
My Type of Life
PDF
The Shifting Nature of FED Role
Making Mixed Reality Living Spaces
A Journey with React
From Box to Bots in Minutes
Building Tools for the Next Web
21st Century Crystal Ball
I HATE YOUR GAME with Bob Heubel
Just Make Stuff!
Getting to Know Grunt By Writing Your Own Plugin
Here Be Dragons – Advanced JavaScript Debugging
The Browser Is Dead, Long Live The Web!
Components are the Future of the Web: It’s Going To Be Okay
I Heard React Was Good
Managing Responsive Design Projects
Squishy pixels
How We Used To, How We Will
The Life of <p>
Reinvent Your Creative Process with Collaborative Hackathons
Your UX is not my UX
My Type of Life
The Shifting Nature of FED Role
Ad

Similar to Functional Web Development (20)

PPTX
ReactJS Code Impact
PDF
Intro to react_v2
PPTX
ReactJS.NET - Fast and Scalable Single Page Applications
PDF
Tech Talk on ReactJS
PPTX
React - An Introduction
PDF
Workshop 19: ReactJS Introduction
PDF
Welcome to React & Flux !
PDF
An Intense Overview of the React Ecosystem
PPTX
Introduction to ReactJS UI Web Dev .pptx
PPTX
Introduction to React JS.pptx
PPTX
ReactJS - Re-rendering pages in the age of the mutable DOM
PDF
Content-Driven Apps with React
PDF
React.js - and how it changed our thinking about UI
PPTX
React.js at Cortex
PDF
An Overview of the React Ecosystem
PPTX
theory-slides-for react for beginners.pptx
PDF
theory-slides-vueh3urh4ur4ur4r44oirj4riu4ri
PPTX
PDF
Integrating React.js with PHP projects
PPTX
Relay: Seamless Syncing for React (VanJS)
ReactJS Code Impact
Intro to react_v2
ReactJS.NET - Fast and Scalable Single Page Applications
Tech Talk on ReactJS
React - An Introduction
Workshop 19: ReactJS Introduction
Welcome to React & Flux !
An Intense Overview of the React Ecosystem
Introduction to ReactJS UI Web Dev .pptx
Introduction to React JS.pptx
ReactJS - Re-rendering pages in the age of the mutable DOM
Content-Driven Apps with React
React.js - and how it changed our thinking about UI
React.js at Cortex
An Overview of the React Ecosystem
theory-slides-for react for beginners.pptx
theory-slides-vueh3urh4ur4ur4r44oirj4riu4ri
Integrating React.js with PHP projects
Relay: Seamless Syncing for React (VanJS)

More from FITC (20)

PPTX
Cut it up
PDF
Designing for Digital Health
PDF
Profiling JavaScript Performance
PPTX
Surviving Your Tech Stack
PDF
How to Pitch Your First AR Project
PDF
Start by Understanding the Problem, Not by Delivering the Answer
PDF
Cocaine to Carrots: The Art of Telling Someone Else’s Story
PDF
Everyday Innovation
PDF
HyperLight Websites
PDF
Everything is Terrifying
PDF
Post-Earth Visions: Designing for Space and the Future Human
PDF
The Rise of the Creative Social Influencer (and How to Become One)
PDF
East of the Rockies: Developing an AR Game
PDF
Creating a Proactive Healthcare System
PDF
World Transformation: The Secret Agenda of Product Design
PDF
The Power of Now
PDF
High Performance PWAs
PDF
Rise of the JAMstack
PDF
From Closed to Open: A Journey of Self Discovery
PDF
Projects Ain’t Nobody Got Time For
Cut it up
Designing for Digital Health
Profiling JavaScript Performance
Surviving Your Tech Stack
How to Pitch Your First AR Project
Start by Understanding the Problem, Not by Delivering the Answer
Cocaine to Carrots: The Art of Telling Someone Else’s Story
Everyday Innovation
HyperLight Websites
Everything is Terrifying
Post-Earth Visions: Designing for Space and the Future Human
The Rise of the Creative Social Influencer (and How to Become One)
East of the Rockies: Developing an AR Game
Creating a Proactive Healthcare System
World Transformation: The Secret Agenda of Product Design
The Power of Now
High Performance PWAs
Rise of the JAMstack
From Closed to Open: A Journey of Self Discovery
Projects Ain’t Nobody Got Time For

Recently uploaded (20)

PPT
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PDF
Sims 4 Historia para lo sims 4 para jugar
PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
PDF
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PDF
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
PDF
Tenda Login Guide: Access Your Router in 5 Easy Steps
PPTX
introduction about ICD -10 & ICD-11 ppt.pptx
PPTX
PptxGenJS_Demo_Chart_20250317130215833.pptx
PPTX
newyork.pptxirantrafgshenepalchinachinane
PPTX
Slides PPTX World Game (s) Eco Economic Epochs.pptx
PPTX
Power Point - Lesson 3_2.pptx grad school presentation
PPTX
Digital Literacy And Online Safety on internet
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PPT
Ethics in Information System - Management Information System
PPTX
E -tech empowerment technologies PowerPoint
PDF
Introduction to the IoT system, how the IoT system works
PPTX
innovation process that make everything different.pptx
PPTX
presentation_pfe-universite-molay-seltan.pptx
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
WebRTC in SignalWire - troubleshooting media negotiation
Sims 4 Historia para lo sims 4 para jugar
Decoding a Decade: 10 Years of Applied CTI Discipline
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
Module 1 - Cyber Law and Ethics 101.pptx
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
Tenda Login Guide: Access Your Router in 5 Easy Steps
introduction about ICD -10 & ICD-11 ppt.pptx
PptxGenJS_Demo_Chart_20250317130215833.pptx
newyork.pptxirantrafgshenepalchinachinane
Slides PPTX World Game (s) Eco Economic Epochs.pptx
Power Point - Lesson 3_2.pptx grad school presentation
Digital Literacy And Online Safety on internet
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
Ethics in Information System - Management Information System
E -tech empowerment technologies PowerPoint
Introduction to the IoT system, how the IoT system works
innovation process that make everything different.pptx
presentation_pfe-universite-molay-seltan.pptx

Functional Web Development

  • 1. FUNCTIONAL WEB DEVELOPMENT - AN INTRODUCTION TO React.js
  • 2. HELLO, MY NAME IS Bertrand KARERANGABO. @BERTRANDK
  • 3. I WORK AT RANGLE.IO
  • 4. Moar functional! — Nick Van Weerdenburg
  • 5. typeof NaN === 'number' //=> true
  • 6. WHAT PROBLEM ARE WE TALKING ABOUT TODAY?
  • 7. Most software today is very much like an Egyptian pyramid with millions of bricks piled on top of each other, with no structural integrity, but just done by brute force and thousands of slaves. — Alan Kay
  • 8. THE PROBLEM HOW CAN WE BUILD LARGE APPLICATIONS WITH DATA THAT CHANGES OVER TIME?
  • 10. ▸ A (very) short history of web development ▸ OOP in the wild ▸ Functional design ▸ React.js ▸ Immutable (data stuctures) ▸ The server (SEO & performance) ▸ The end
  • 11. 1979 · MODEL-VIEW-CONTROLLER IS BORN It was fist articulated by Trygve Reenskaug, Adele Goldberg and others at Xeroc PARC. MVC was conceived as a general solution to the problem of users controlling a large and complex data set.
  • 12. MVC AND IT'S LATER VARIANTS HAVE ALL INHERITED FROM THE INITIAL OOP-BASED IMPLEMENTATION.
  • 13. 1990 · THE FIRST WEB BROWSER It was invented by Tim Berners-Lee and was initially called WorldWideWeb. ▸ It was written in Objective-C. ▸ It introduced an Internet-based document system called HyperText Markup Language. ▸ The layout engine was a subclass of NeXTSTEP's Text class. ▸ The document is static – if data changes, you must refresh!
  • 14. 1995 · THE FIRST DOM The Level 0 DOM was created by Netscape for Netscape Navigator 2.0. The idea was to give web developers a means by which to allow users to interact with a site. Given that an HTML document can be represented as a tree, the DOM API allows for developers to interact and manipulate the tree's nodes.
  • 15. 1995 · THE FIRST JAVASCRIPT
  • 16. ▸ A (very) short history of web development ▸ OOP in the wild ▸ Functional design ▸ React.js ▸ Immutable (data stuctures) ▸ The server (SEO & performance) ▸ The end
  • 18. A SHOPPING CART - OOP DATA
  • 19. A SHOPPING CART - OOP DATA & METHODS
  • 20. Local state that changes over time is the root of all evil.
  • 21. A BASIC COMPUTER IN 1995 Ram: 8MB HDD: 1GB CPU: 33MHz
  • 22. LET'S NOT WRITE SOFTWARE LIKE IT'S 1995.
  • 23. WE NEED A BETTER ABSTRACTION
  • 24. ▸ A (very) short history of web development ▸ OOP in the wild ▸ Functional design ▸ React.js ▸ Immutable (data stuctures) ▸ The server (SEO & performance) ▸ The end
  • 25. A SHOPPING CART - FP DATA
  • 26. A SHOPPING CART - FP DATA
  • 27. A SOLUTION REACT.JS + IMMUTABLE-JS
  • 28. ▸ A (very) short history of web development ▸ OOP in the wild ▸ Functional design ▸ React.js ▸ Immutable (data stuctures) ▸ The server (SEO & performance) ▸ The end
  • 29. REACT.JS A JAVASCRIPT LIBRARY FOR BUILDING COMPOSABLE USER INTERFACES
  • 30. REACT.JS VIRTUAL DOM The full DOM API in JavaScript. When rendering, it uses a diff implementation for ultra-high performance. f(newDOM, oldDOM) = Δ
  • 31. REACT.JS COMPONENT var App = React.createClass({ render: function() { return React.DOM.h1(null, 'Hello'); }; });
  • 32. REACT.JS RENDER var App = React.createClass({ render: function() { return React.DOM.h1(null, 'Hello'); }; }); React.renderComponent(App(null), document.body);
  • 33. REACT.JS PROPS var french = 'Allo'; var App = React.createClass({ render: function() { return React.DOM.h1(null, this.props.salutation ); }; }); React.renderComponent(App({ salutation: french }), document.body);
  • 34. REACT.JS DOM PROPERTIES var french = 'Allo'; var App = React.createClass({ render: function() { return React.DOM.h1({ className: 'title' }, this.props.salutation ); }; }); React.renderComponent(App({ salutation: french }), document.body);
  • 35. REACT.JS EVENTS var french = 'Allo'; function scream() { alert("I've been clicked!"); } var App = React.createClass({ render: function() { return React.DOM.h1({ className: 'title', onClick: this.props.clickHandler }, this.props.salutation ); }; }); React.renderComponent(App({ salutation: french, clickHandler: scream }), document.body);
  • 36. REACT.JS STATE* var french = 'Allo'; var App = React.createClass({ getInitialState: function() { return { name: 'Unknown' }; }, componentDidMount: function() { $.ajax({ url: '/me', dataType: 'json', success: function(data) { this.setState({ name: data }); }.bind(this); }); }, render: function() { var fullSalutation = this.props.salutation + ', ' + this.state.name; return React.DOM.h1(null, fullSalutation); }; }); React.renderComponent(App({ salutation: french }), document.body);
  • 37. REACT.JS COMPONENT SPECIFICATION - render - getInitialState - getDefaultProps - propTypes - mixins - statics - displayName
  • 38. REACT.JS COMPONENT LIFECYCLE Mounting: - componentWillMount - componentDidMount Updating: - componentWillReceiveProps - shouldComponentUpdate - componentWillUpdate - componentDidUpdate Unmounting: - componentWillUnmount
  • 40. ▸ A (very) short history of web development ▸ OOP in the wild ▸ Functional design ▸ React.js ▸ Immutable (data stuctures) ▸ The server (SEO & performance) ▸ The end
  • 41. IMMUTABLE IMMUTABLE AND PERSISTENT DATA STRUCTURES + SUPPORTING APIS
  • 42. IMMUTABLE MAPS var map1 = Immutable.Map({ a: 1, b: 2, c: 3 }); map2 = map.set('b', 20); // note the assignment map2.get('b'); // 20 map1.get('b'); // 2
  • 43. IMMUTABLE VECTOR var vect1 = Immutable.Vector(1, 2); var vect2 = vect1.push(3, 4, 5); var vect3 = vect2.unshift(0); var vect4 = vect1.concat(vect2, vect3); assert(vect1.length === 2); assert(vect2.length === 5); assert(vect3.length === 6); assert(vect4.length === 13); assert(vect4.get(0) === 1);
  • 44. IMMUTABLE EQUALITY var map1 = Immutable.Map({a:1, b:1, c:1}); var map2 = Immutable.Map({a:1, b:1, c:1}); assert(map1 !== map2); assert(Immutable.is(map1, map2) === true);
  • 45. IMMUTABLE INTEROP var deep = Immutable.Map({a:1, b:2, c:Immutable.Vector(3,4,5)}); deep.toObject() // { a: 1, b: 2, c: Vector [ 3, 4, 5 ] } deep.toArray() // [ 1, 2, Vector [ 3, 4, 5 ] ] deep.toJS() // { a: 1, b: 2, c: [ 3, 4, 5 ] } JSON.stringify(deep) // '{"a":1,"b":2,"c":[3,4,5]}'
  • 46. IMMUTABLE CURSORS var appData = Immutable.fromJS({ a: { b: { c: 1 } } }); var userData = appData.cursor(['a', 'b', 'c'], function(newData) { appData = newData; }); // ... elsewhere ... userData.deref(); // 1 userData = userData.update(function(x) { return x + 1 }); userData.deref(); // 2 // ... back to data ... appData.getIn(['a', 'b', 'c']); // 2
  • 48. ▸ A (very) short history of web development ▸ OOP in the wild ▸ Functional design ▸ React.js ▸ Immutable (data stuctures) ▸ The server (SEO & performance) ▸ The end
  • 49. SERVER-SIDE RENDERING var url = require('url') function(req, res, next) { // get the application path/stage var path = url.parse(req.url).pathname; // get a React.js component var app = App({path: path}); // render component into string instead of DOM var markup = React.renderComponentToString(app); // return full html and let client-side takeover res.send(markup); }
  • 50. ▸ A (very) short history of web development ▸ OOP in the wild ▸ Functional design ▸ React.js ▸ Immutable (data stuctures) ▸ The server (SEO & performance) ▸ The end
  • 51. WE NOW HAVE SOLID MODEL FOR DATA THAT CHANGES OVER TIME.
  • 52. MIND THE PUNCHLINE It's not important that the chicken crossed the road or even how it did it. What's important is why it crossed the road.