SlideShare a Scribd company logo
Why React is different
Jake Ginnivan
jake@ginnivan.net
http://jake.ginnivan.net
@jakeginnivan
http://github.com/jakeginnivan
Rob Ashton
History of web UI’s
Javascript
<input id="task" type="input" />
<input id="addTask" type="button" onClick="addTask()" value="add" />
<ul id="tasks"></ul>
<script type="text/javascript">
function addTask() {
var task = document.createElement('li')
var input = document.getElementById('task')
task.innerText = input.value
input.value = '' document.body.appendChild(task)
}
</script>
jQuery
<input id="task" type="input" />
<input id="addTask" type="button" value="add" />
<ul id="tasks"></ul>
<script type="text/javascript" src="https://code.jquery.com/jquery-
1.11.3.min.js"></script>
<script type="text/javascript">
$(function() {
$('#addTask').click(function() {
var input = $('#task')
$(document.body).append('<li>' + input.val() + '</li>')
input.val('')
})
})
</script>
Templating libraries
<script src="jquery-1.11.3.min.js"></script><script src="handlebars.min.js"></script>
<script type="text/template" id="tasks-list-template">
{{#each tasks}}
<li>{{this}}</li>
{{/each}}
</script>
<script type="text/javascript">
$(function() {
var tasks = []
var source = $('#tasks-list-template').html()
var template = Handlebars.compile(source)
$('#addTask').click(function() {
var input = $('#task')
var task = input.val()
tasks.push(task)
$('#tasks').html(template({tasks: tasks}))
input.val('')
})
})
</script>
function template(context) {
return context.tasks.map(function(task) {
return '<li>' + task + '</li>;'
})
}
Data binding
<ul id="tasks" data-bind="template: { name: 'task-template', foreach: tasks }">
<li data-bind="text: $data"></li>
</ul>
<script src="jquery-1.11.3.min.js"></script><script src="knockout-min.js"></script>
<script type="text/template" id="task-template">
<li data-bind="text: $data"></li>
</script>
<script type="text/javascript">
$(function() {
var tasksViewModel = { tasks: ko.observableArray([]) }
ko.applyBindings(tasksViewModel)
$("#addTask").click(function() {
var input = $("#task")
var task = input.val()
tasksViewModel.tasks.push(task)
input.val('')
})
})
</script>
WebComponents
<div task-list /> <TaskList />
Directives
They are all basically the same…..
React actually is different!
ES6 Primer!
class Foo {
method() { console.log('Hi DDD') }
}
function Foo() { }
Foo.prototype.method = function() {
console.log('Hi DDD')
}
array.map(i => console.log(i)) array.map(function(i) { console.log(i) })
import foo from 'foo' var foo = require('foo')
export default function() { } module.exports = function() { }
So what is React?
class TaskList extends React.Component {
constructor(props) {
super(props)
this.state = { tasks: [], newTask: '' }
}
newTaskTextChanged(e) { this.setState({newTask: e.target.value}) }
addTask() {
this.setState({ tasks: this.state.tasks.splice(0, 0, this.state.newTask), newTask: '' })
}
render() {
return (
<div>
<input type="text" onChange={this.newTaskTextChanged} />
<ul>{this.state.tasks.map(t => <li onClick={this.addTask}>{t}</li>)}</ul>
</div>
)
}
}
var container = document.body.createElement('div')
document.body.appendChild(container)
React.render(<TaskList />, container)
So what is React?
class TaskList extends React.Component {
constructor(props) {
super(props)
this.state = { tasks: [], newTask: '' }
}
newTaskTextChanged(e) { this.setState({newTask: e.target.value}) }
addTask() {
this.setState({ tasks: this.state.tasks.splice(0, 0, this.state.newTask), newTask: '' })
}
render() {
return (
<div>
<input type="text" onChange={this.newTaskTextChanged} />
<ul>{this.state.tasks.map(t => <li onClick={this.addTask}>{t}</li>)}</ul>
</div>
)
}
}
var container = document.body.createElement('div')
document.body.appendChild(container)
React.render(<TaskList />, container)
So what is React?
class TaskList extends React.Component {
constructor(props) {
super(props)
this.state = { tasks: [], newTask: '' }
}
newTaskTextChanged(e) { this.setState({newTask: e.target.value}) }
addTask() {
this.setState({ tasks: this.state.tasks.splice(0, 0, this.state.newTask), newTask: '' })
}
render() {
return (
<div>
<input type="text" onChange={this.newTaskTextChanged} />
<ul>{this.state.tasks.map(t => <li onClick={this.addTask}>{t}</li>)}</ul>
</div>
)
}
}
var container = document.body.createElement('div')
document.body.appendChild(container)
React.render(<TaskList />, container)
So what is React?
class TaskList extends React.Component {
constructor(props) {
super(props)
this.state = { tasks: [], newTask: '' }
}
newTaskTextChanged(e) { this.setState({newTask: e.target.value}) }
addTask() {
this.setState({ tasks: this.state.tasks.splice(0, 0, this.state.newTask), newTask: '' })
}
render() {
return (
<div>
<input type="text" onChange={this.newTaskTextChanged} />
<ul>{this.state.tasks.map(t => <li onClick={this.addTask}>{t}</li>)}</ul>
</div>
)
}
}
var container = document.body.createElement('div')
document.body.appendChild(container)
React.render(<TaskList />, container)
What the hell is that??
You have put HTML in my JavaScript
http://codepen.io/somethingkindawierd/blog/jsx-is-weird
What the hell is that??
render() {
return (
React.createElement("div", null,
React.createElement("input", {type: "text", onChange: this.newTaskTextChanged}),
React.createElement(
"ul",
null,
this.state.tasks.map(t => React.createElement("li", {onClick: this.addTask}, t))
)
)
)
}
But, but separation of concerns!?!
Markup + display logic are highly cohesive and tightly coupled.
We are separating technologies at the moment, not concerns
Everything is JavaScript
• Lets accept templating languages are underpowered
• And inventing dsl's to specify bindings are just recreating what we already have
• Everything you can do in javascript you can now do in your markup
• Extract bits of markup into variables
• Simple display logic (item/items)
• No parsing/eval and text automatically html encoded - no xss
• Up to you how to separate your concerns!
Angular…
<ul ng-repeat="task in tasks"}><li ng-bind="task"></li></ul>
<ng-pluralize count="personCount"
when="{'0': 'Nobody is viewing.',
'one': '1 person is viewing.',
'other': '{} people are viewing.'}">
</ng-pluralize>
<div ng-if="conference === 'dddperth'">Hi DDD Perth</div>
React's design
Our intellectual powers are rather geared to master static relations
and that our powers to visualise processes evolving in time are
relatively poorly developed. For that reason we should do (as wise
programmers aware of our limitations) our utmost to shorten the
conceptual gap between the static program and the dynamic
process, to make the correspondence between the program (spread
out in text space) and the process (spread out in time) as trivial as
possible.
- Dijkstra
From <https://en.wikiquote.org/wiki/Edsger_W._Dijkstra>
React's design
Our intellectual powers are rather geared to master static relations
and that our powers to visualise processes evolving in time are
relatively poorly developed. For that reason we should do (as wise
programmers aware of our limitations) our utmost to shorten the
conceptual gap between the static program and the dynamic
process, to make the correspondence between the program (spread
out in text space) and the process (spread out in time) as trivial as
possible.
- Dijkstra
From <https://en.wikiquote.org/wiki/Edsger_W._Dijkstra>
React's design
Application State render() Rendered Application
Event (DOM, Push Messaging etc)
Event
Handler
New State
Virtual DOM
<ul>
<li key="1">Task 1</li>
<li key="2">Task 2</li>
</ul>
<ul>
<li key="1">Task 1</li>
<li key="2">Task 2</li>
<li key="3">Task 3</li>
</ul>
PATCH:
Insert <li key="3">Task 3</li> at end of <ul>
Delete li with key "1"
<ul>
<li key="2">Task 2</li>
<li key="3">Task 3</li>
</ul>
<ul>
<li key="2">Task 2</li>
<li key="3">Task 3</li>
</ul>
Virtual DOM != Shadow DOM
• <input id="foo" type="range">
• It renders a complex control
• foo.childElement === null
• CSS can be scoped to that Shadow DOM
Breaking React down
We can actually cover the entire library surface in 10 minutes.. Try doing that with
angular/ember
Components!
Anatomy of a React Component
Lets code a simple React component
Lifecycle of a React Component
First Render
initial state/props
componentWillMount
componentDidMount
componentWillUnmount
Props changed
componentWillReceiveProps
shouldComponentUpdate
componentWillUpdate
render
componentDidUpdate
state changed
shouldComponentUpdate
componentWillUpdate
render
componentDidUpdate
Other things
Styles
render() {
return (
<div>
<span style={{color: 'red'}}
className="myClass">text</a>
</div>
)
}
Styles
render() {
var red = {color: 'red'}
var classes = classNames(['classOne', something ? 'classTwo' : null])
return (
<div>
<span style={red}
className={classes}>text</a>
</div>
)
}
Styles
import myStyles from './component.less'
render() {return (
<div>
<span className={myStyle.someClass}>text</a>
</div>
)
}
Isomorphic
• The same React components can render on the server AND on the
client
• When client initialises, it:
• attaches to the server generated dom
• Generates the initial Virtual DOM from that
• Renders a complete new VDOM
• Brings server generated DOM up to date
Testing
• Shallow Rendering
• Render into DOM
• Test tools available
Show me something decent
Ok..
Here is Reactive Trader
Wrapping up
• https://github.com/AdaptiveConsulting/react-adaptive-trader
Questions?
Why react is different

More Related Content

What's hot

React JS and Redux
React JS and ReduxReact JS and Redux
React JS and Redux
Glib Kechyn
 
Better web apps with React and Redux
Better web apps with React and ReduxBetter web apps with React and Redux
Better web apps with React and Redux
Ali Sa'o
 
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Luciano Mammino
 
ReactJs presentation
ReactJs presentationReactJs presentation
ReactJs presentation
nishasowdri
 
React state managmenet with Redux
React state managmenet with ReduxReact state managmenet with Redux
React state managmenet with Redux
Vedran Blaženka
 
Switch to React.js from AngularJS developer
Switch to React.js from AngularJS developerSwitch to React.js from AngularJS developer
Switch to React.js from AngularJS developer
Eugene Zharkov
 
Introduction to Redux
Introduction to ReduxIntroduction to Redux
Introduction to Redux
Ignacio Martín
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
WebStackAcademy
 
React with Redux
React with ReduxReact with Redux
React with Redux
Stanimir Todorov
 
Linked In Presentation
Linked In PresentationLinked In Presentation
Linked In Presentation
apweir12
 
React.js or why DOM finally makes sense
React.js or why DOM finally makes senseReact.js or why DOM finally makes sense
React.js or why DOM finally makes sense
Eldar Djafarov
 
React for Dummies
React for DummiesReact for Dummies
React for Dummies
Mitch Chen
 
React / Redux Architectures
React / Redux ArchitecturesReact / Redux Architectures
React / Redux Architectures
Vinícius Ribeiro
 
Academy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingAcademy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & Tooling
Binary Studio
 
Let's Redux!
Let's Redux!Let's Redux!
Let's Redux!
Joseph Chiang
 
React, Flux and a little bit of Redux
React, Flux and a little bit of ReduxReact, Flux and a little bit of Redux
React, Flux and a little bit of Redux
Ny Fanilo Andrianjafy, B.Eng.
 
Intro to ReactJS
Intro to ReactJSIntro to ReactJS
Intro to ReactJS
Harvard Web Working Group
 
An Introduction to ReactJS
An Introduction to ReactJSAn Introduction to ReactJS
An Introduction to ReactJS
All Things Open
 
ReactJS for Beginners
ReactJS for BeginnersReactJS for Beginners
ReactJS for Beginners
Oswald Campesato
 
React.js and Redux overview
React.js and Redux overviewReact.js and Redux overview
React.js and Redux overview
Alex Bachuk
 

What's hot (20)

React JS and Redux
React JS and ReduxReact JS and Redux
React JS and Redux
 
Better web apps with React and Redux
Better web apps with React and ReduxBetter web apps with React and Redux
Better web apps with React and Redux
 
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
 
ReactJs presentation
ReactJs presentationReactJs presentation
ReactJs presentation
 
React state managmenet with Redux
React state managmenet with ReduxReact state managmenet with Redux
React state managmenet with Redux
 
Switch to React.js from AngularJS developer
Switch to React.js from AngularJS developerSwitch to React.js from AngularJS developer
Switch to React.js from AngularJS developer
 
Introduction to Redux
Introduction to ReduxIntroduction to Redux
Introduction to Redux
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
 
React with Redux
React with ReduxReact with Redux
React with Redux
 
Linked In Presentation
Linked In PresentationLinked In Presentation
Linked In Presentation
 
React.js or why DOM finally makes sense
React.js or why DOM finally makes senseReact.js or why DOM finally makes sense
React.js or why DOM finally makes sense
 
React for Dummies
React for DummiesReact for Dummies
React for Dummies
 
React / Redux Architectures
React / Redux ArchitecturesReact / Redux Architectures
React / Redux Architectures
 
Academy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingAcademy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & Tooling
 
Let's Redux!
Let's Redux!Let's Redux!
Let's Redux!
 
React, Flux and a little bit of Redux
React, Flux and a little bit of ReduxReact, Flux and a little bit of Redux
React, Flux and a little bit of Redux
 
Intro to ReactJS
Intro to ReactJSIntro to ReactJS
Intro to ReactJS
 
An Introduction to ReactJS
An Introduction to ReactJSAn Introduction to ReactJS
An Introduction to ReactJS
 
ReactJS for Beginners
ReactJS for BeginnersReactJS for Beginners
ReactJS for Beginners
 
React.js and Redux overview
React.js and Redux overviewReact.js and Redux overview
React.js and Redux overview
 

Similar to Why react is different

Modern frontend development with VueJs
Modern frontend development with VueJsModern frontend development with VueJs
Modern frontend development with VueJs
Tudor Barbu
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
Nikolaus Graf
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
toddbr
 
Client Web
Client WebClient Web
Client Web
Markiyan Matsekh
 
An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.js
Emanuele DelBono
 
Knockout.js presentation
Knockout.js presentationKnockout.js presentation
Knockout.js presentation
Scott Messinger
 
How to Mess Up Your Angular UI Components
How to Mess Up Your Angular UI ComponentsHow to Mess Up Your Angular UI Components
How to Mess Up Your Angular UI Components
cagataycivici
 
Backbone - TDC 2011 Floripa
Backbone - TDC 2011 FloripaBackbone - TDC 2011 Floripa
Backbone - TDC 2011 Floripa
Rafael Felix da Silva
 
Introduction to React and MobX
Introduction to React and MobXIntroduction to React and MobX
Introduction to React and MobX
Anjali Chawla
 
React/Redux
React/ReduxReact/Redux
React/Redux
Durgesh Vaishnav
 
Creating lightweight JS Apps w/ Web Components and lit-html
Creating lightweight JS Apps w/ Web Components and lit-htmlCreating lightweight JS Apps w/ Web Components and lit-html
Creating lightweight JS Apps w/ Web Components and lit-html
Ilia Idakiev
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
pootsbook
 
CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35
Bilal Ahmed
 
Scala based Lift Framework
Scala based Lift FrameworkScala based Lift Framework
Scala based Lift Framework
vhazrati
 
Overview Of Lift Framework
Overview Of Lift FrameworkOverview Of Lift Framework
Overview Of Lift Framework
Xebia IT Architects
 
Overview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkOverview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web Framework
IndicThreads
 
Reactive Type-safe WebComponents
Reactive Type-safe WebComponentsReactive Type-safe WebComponents
Reactive Type-safe WebComponents
Martin Hochel
 
Lecture 6: Client Side Programming 2
Lecture 6: Client Side Programming 2Lecture 6: Client Side Programming 2
Lecture 6: Client Side Programming 2
Artificial Intelligence Institute at UofSC
 
Jquery examples
Jquery examplesJquery examples
Jquery examples
programmingslides
 
Unit3.pptx
Unit3.pptxUnit3.pptx
Unit3.pptx
AnamikaRai59
 

Similar to Why react is different (20)

Modern frontend development with VueJs
Modern frontend development with VueJsModern frontend development with VueJs
Modern frontend development with VueJs
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
Client Web
Client WebClient Web
Client Web
 
An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.js
 
Knockout.js presentation
Knockout.js presentationKnockout.js presentation
Knockout.js presentation
 
How to Mess Up Your Angular UI Components
How to Mess Up Your Angular UI ComponentsHow to Mess Up Your Angular UI Components
How to Mess Up Your Angular UI Components
 
Backbone - TDC 2011 Floripa
Backbone - TDC 2011 FloripaBackbone - TDC 2011 Floripa
Backbone - TDC 2011 Floripa
 
Introduction to React and MobX
Introduction to React and MobXIntroduction to React and MobX
Introduction to React and MobX
 
React/Redux
React/ReduxReact/Redux
React/Redux
 
Creating lightweight JS Apps w/ Web Components and lit-html
Creating lightweight JS Apps w/ Web Components and lit-htmlCreating lightweight JS Apps w/ Web Components and lit-html
Creating lightweight JS Apps w/ Web Components and lit-html
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
 
CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35
 
Scala based Lift Framework
Scala based Lift FrameworkScala based Lift Framework
Scala based Lift Framework
 
Overview Of Lift Framework
Overview Of Lift FrameworkOverview Of Lift Framework
Overview Of Lift Framework
 
Overview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkOverview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web Framework
 
Reactive Type-safe WebComponents
Reactive Type-safe WebComponentsReactive Type-safe WebComponents
Reactive Type-safe WebComponents
 
Lecture 6: Client Side Programming 2
Lecture 6: Client Side Programming 2Lecture 6: Client Side Programming 2
Lecture 6: Client Side Programming 2
 
Jquery examples
Jquery examplesJquery examples
Jquery examples
 
Unit3.pptx
Unit3.pptxUnit3.pptx
Unit3.pptx
 

Recently uploaded

Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom KittEnhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Peter Caitens
 
Strengthening Web Development with CommandBox 6: Seamless Transition and Scal...
Strengthening Web Development with CommandBox 6: Seamless Transition and Scal...Strengthening Web Development with CommandBox 6: Seamless Transition and Scal...
Strengthening Web Development with CommandBox 6: Seamless Transition and Scal...
Ortus Solutions, Corp
 
Folding Cheat Sheet #5 - fifth in a series
Folding Cheat Sheet #5 - fifth in a seriesFolding Cheat Sheet #5 - fifth in a series
Folding Cheat Sheet #5 - fifth in a series
Philip Schwarz
 
Superpower Your Apache Kafka Applications Development with Complementary Open...
Superpower Your Apache Kafka Applications Development with Complementary Open...Superpower Your Apache Kafka Applications Development with Complementary Open...
Superpower Your Apache Kafka Applications Development with Complementary Open...
Paul Brebner
 
Refactoring legacy systems using events commands and bubble contexts
Refactoring legacy systems using events commands and bubble contextsRefactoring legacy systems using events commands and bubble contexts
Refactoring legacy systems using events commands and bubble contexts
Michał Kurzeja
 
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Paul Brebner
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
kalichargn70th171
 
ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.
Maitrey Patel
 
What is Continuous Testing in DevOps - A Definitive Guide.pdf
What is Continuous Testing in DevOps - A Definitive Guide.pdfWhat is Continuous Testing in DevOps - A Definitive Guide.pdf
What is Continuous Testing in DevOps - A Definitive Guide.pdf
kalichargn70th171
 
Best Practices & Tips for a Successful Odoo ERP Implementation
Best Practices & Tips for a Successful Odoo ERP ImplementationBest Practices & Tips for a Successful Odoo ERP Implementation
Best Practices & Tips for a Successful Odoo ERP Implementation
Envertis Software Solutions
 
Upturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in NashikUpturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in Nashik
Upturn India Technologies
 
What’s New in VictoriaLogs - Q2 2024 Update
What’s New in VictoriaLogs - Q2 2024 UpdateWhat’s New in VictoriaLogs - Q2 2024 Update
What’s New in VictoriaLogs - Q2 2024 Update
VictoriaMetrics
 
Streamlining End-to-End Testing Automation
Streamlining End-to-End Testing AutomationStreamlining End-to-End Testing Automation
Streamlining End-to-End Testing Automation
Anand Bagmar
 
42 Ways to Generate Real Estate Leads - Sellxpert
42 Ways to Generate Real Estate Leads - Sellxpert42 Ways to Generate Real Estate Leads - Sellxpert
42 Ways to Generate Real Estate Leads - Sellxpert
vaishalijagtap12
 
What’s new in VictoriaMetrics - Q2 2024 Update
What’s new in VictoriaMetrics - Q2 2024 UpdateWhat’s new in VictoriaMetrics - Q2 2024 Update
What’s new in VictoriaMetrics - Q2 2024 Update
VictoriaMetrics
 
Boost Your Savings with These Money Management Apps
Boost Your Savings with These Money Management AppsBoost Your Savings with These Money Management Apps
Boost Your Savings with These Money Management Apps
Jhone kinadey
 
Going AOT: Everything you need to know about GraalVM for Java applications
Going AOT: Everything you need to know about GraalVM for Java applicationsGoing AOT: Everything you need to know about GraalVM for Java applications
Going AOT: Everything you need to know about GraalVM for Java applications
Alina Yurenko
 
Building the Ideal CI-CD Pipeline_ Achieving Visual Perfection
Building the Ideal CI-CD Pipeline_ Achieving Visual PerfectionBuilding the Ideal CI-CD Pipeline_ Achieving Visual Perfection
Building the Ideal CI-CD Pipeline_ Achieving Visual Perfection
Applitools
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
ervikas4
 
Cost-Effective Strategies For iOS App Development
Cost-Effective Strategies For iOS App DevelopmentCost-Effective Strategies For iOS App Development
Cost-Effective Strategies For iOS App Development
Softradix Technologies
 

Recently uploaded (20)

Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom KittEnhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
 
Strengthening Web Development with CommandBox 6: Seamless Transition and Scal...
Strengthening Web Development with CommandBox 6: Seamless Transition and Scal...Strengthening Web Development with CommandBox 6: Seamless Transition and Scal...
Strengthening Web Development with CommandBox 6: Seamless Transition and Scal...
 
Folding Cheat Sheet #5 - fifth in a series
Folding Cheat Sheet #5 - fifth in a seriesFolding Cheat Sheet #5 - fifth in a series
Folding Cheat Sheet #5 - fifth in a series
 
Superpower Your Apache Kafka Applications Development with Complementary Open...
Superpower Your Apache Kafka Applications Development with Complementary Open...Superpower Your Apache Kafka Applications Development with Complementary Open...
Superpower Your Apache Kafka Applications Development with Complementary Open...
 
Refactoring legacy systems using events commands and bubble contexts
Refactoring legacy systems using events commands and bubble contextsRefactoring legacy systems using events commands and bubble contexts
Refactoring legacy systems using events commands and bubble contexts
 
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
 
ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.
 
What is Continuous Testing in DevOps - A Definitive Guide.pdf
What is Continuous Testing in DevOps - A Definitive Guide.pdfWhat is Continuous Testing in DevOps - A Definitive Guide.pdf
What is Continuous Testing in DevOps - A Definitive Guide.pdf
 
Best Practices & Tips for a Successful Odoo ERP Implementation
Best Practices & Tips for a Successful Odoo ERP ImplementationBest Practices & Tips for a Successful Odoo ERP Implementation
Best Practices & Tips for a Successful Odoo ERP Implementation
 
Upturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in NashikUpturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in Nashik
 
What’s New in VictoriaLogs - Q2 2024 Update
What’s New in VictoriaLogs - Q2 2024 UpdateWhat’s New in VictoriaLogs - Q2 2024 Update
What’s New in VictoriaLogs - Q2 2024 Update
 
Streamlining End-to-End Testing Automation
Streamlining End-to-End Testing AutomationStreamlining End-to-End Testing Automation
Streamlining End-to-End Testing Automation
 
42 Ways to Generate Real Estate Leads - Sellxpert
42 Ways to Generate Real Estate Leads - Sellxpert42 Ways to Generate Real Estate Leads - Sellxpert
42 Ways to Generate Real Estate Leads - Sellxpert
 
What’s new in VictoriaMetrics - Q2 2024 Update
What’s new in VictoriaMetrics - Q2 2024 UpdateWhat’s new in VictoriaMetrics - Q2 2024 Update
What’s new in VictoriaMetrics - Q2 2024 Update
 
Boost Your Savings with These Money Management Apps
Boost Your Savings with These Money Management AppsBoost Your Savings with These Money Management Apps
Boost Your Savings with These Money Management Apps
 
Going AOT: Everything you need to know about GraalVM for Java applications
Going AOT: Everything you need to know about GraalVM for Java applicationsGoing AOT: Everything you need to know about GraalVM for Java applications
Going AOT: Everything you need to know about GraalVM for Java applications
 
Building the Ideal CI-CD Pipeline_ Achieving Visual Perfection
Building the Ideal CI-CD Pipeline_ Achieving Visual PerfectionBuilding the Ideal CI-CD Pipeline_ Achieving Visual Perfection
Building the Ideal CI-CD Pipeline_ Achieving Visual Perfection
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
 
Cost-Effective Strategies For iOS App Development
Cost-Effective Strategies For iOS App DevelopmentCost-Effective Strategies For iOS App Development
Cost-Effective Strategies For iOS App Development
 

Why react is different

  • 1. Why React is different
  • 3.
  • 5.
  • 6.
  • 7.
  • 8. History of web UI’s
  • 9.
  • 10. Javascript <input id="task" type="input" /> <input id="addTask" type="button" onClick="addTask()" value="add" /> <ul id="tasks"></ul> <script type="text/javascript"> function addTask() { var task = document.createElement('li') var input = document.getElementById('task') task.innerText = input.value input.value = '' document.body.appendChild(task) } </script>
  • 11. jQuery <input id="task" type="input" /> <input id="addTask" type="button" value="add" /> <ul id="tasks"></ul> <script type="text/javascript" src="https://code.jquery.com/jquery- 1.11.3.min.js"></script> <script type="text/javascript"> $(function() { $('#addTask').click(function() { var input = $('#task') $(document.body).append('<li>' + input.val() + '</li>') input.val('') }) }) </script>
  • 12. Templating libraries <script src="jquery-1.11.3.min.js"></script><script src="handlebars.min.js"></script> <script type="text/template" id="tasks-list-template"> {{#each tasks}} <li>{{this}}</li> {{/each}} </script> <script type="text/javascript"> $(function() { var tasks = [] var source = $('#tasks-list-template').html() var template = Handlebars.compile(source) $('#addTask').click(function() { var input = $('#task') var task = input.val() tasks.push(task) $('#tasks').html(template({tasks: tasks})) input.val('') }) }) </script> function template(context) { return context.tasks.map(function(task) { return '<li>' + task + '</li>;' }) }
  • 13. Data binding <ul id="tasks" data-bind="template: { name: 'task-template', foreach: tasks }"> <li data-bind="text: $data"></li> </ul> <script src="jquery-1.11.3.min.js"></script><script src="knockout-min.js"></script> <script type="text/template" id="task-template"> <li data-bind="text: $data"></li> </script> <script type="text/javascript"> $(function() { var tasksViewModel = { tasks: ko.observableArray([]) } ko.applyBindings(tasksViewModel) $("#addTask").click(function() { var input = $("#task") var task = input.val() tasksViewModel.tasks.push(task) input.val('') }) }) </script>
  • 14. WebComponents <div task-list /> <TaskList /> Directives
  • 15. They are all basically the same….. React actually is different!
  • 16. ES6 Primer! class Foo { method() { console.log('Hi DDD') } } function Foo() { } Foo.prototype.method = function() { console.log('Hi DDD') } array.map(i => console.log(i)) array.map(function(i) { console.log(i) }) import foo from 'foo' var foo = require('foo') export default function() { } module.exports = function() { }
  • 17. So what is React? class TaskList extends React.Component { constructor(props) { super(props) this.state = { tasks: [], newTask: '' } } newTaskTextChanged(e) { this.setState({newTask: e.target.value}) } addTask() { this.setState({ tasks: this.state.tasks.splice(0, 0, this.state.newTask), newTask: '' }) } render() { return ( <div> <input type="text" onChange={this.newTaskTextChanged} /> <ul>{this.state.tasks.map(t => <li onClick={this.addTask}>{t}</li>)}</ul> </div> ) } } var container = document.body.createElement('div') document.body.appendChild(container) React.render(<TaskList />, container)
  • 18. So what is React? class TaskList extends React.Component { constructor(props) { super(props) this.state = { tasks: [], newTask: '' } } newTaskTextChanged(e) { this.setState({newTask: e.target.value}) } addTask() { this.setState({ tasks: this.state.tasks.splice(0, 0, this.state.newTask), newTask: '' }) } render() { return ( <div> <input type="text" onChange={this.newTaskTextChanged} /> <ul>{this.state.tasks.map(t => <li onClick={this.addTask}>{t}</li>)}</ul> </div> ) } } var container = document.body.createElement('div') document.body.appendChild(container) React.render(<TaskList />, container)
  • 19. So what is React? class TaskList extends React.Component { constructor(props) { super(props) this.state = { tasks: [], newTask: '' } } newTaskTextChanged(e) { this.setState({newTask: e.target.value}) } addTask() { this.setState({ tasks: this.state.tasks.splice(0, 0, this.state.newTask), newTask: '' }) } render() { return ( <div> <input type="text" onChange={this.newTaskTextChanged} /> <ul>{this.state.tasks.map(t => <li onClick={this.addTask}>{t}</li>)}</ul> </div> ) } } var container = document.body.createElement('div') document.body.appendChild(container) React.render(<TaskList />, container)
  • 20. So what is React? class TaskList extends React.Component { constructor(props) { super(props) this.state = { tasks: [], newTask: '' } } newTaskTextChanged(e) { this.setState({newTask: e.target.value}) } addTask() { this.setState({ tasks: this.state.tasks.splice(0, 0, this.state.newTask), newTask: '' }) } render() { return ( <div> <input type="text" onChange={this.newTaskTextChanged} /> <ul>{this.state.tasks.map(t => <li onClick={this.addTask}>{t}</li>)}</ul> </div> ) } } var container = document.body.createElement('div') document.body.appendChild(container) React.render(<TaskList />, container)
  • 21. What the hell is that?? You have put HTML in my JavaScript http://codepen.io/somethingkindawierd/blog/jsx-is-weird
  • 22. What the hell is that?? render() { return ( React.createElement("div", null, React.createElement("input", {type: "text", onChange: this.newTaskTextChanged}), React.createElement( "ul", null, this.state.tasks.map(t => React.createElement("li", {onClick: this.addTask}, t)) ) ) ) }
  • 23. But, but separation of concerns!?! Markup + display logic are highly cohesive and tightly coupled. We are separating technologies at the moment, not concerns
  • 24. Everything is JavaScript • Lets accept templating languages are underpowered • And inventing dsl's to specify bindings are just recreating what we already have • Everything you can do in javascript you can now do in your markup • Extract bits of markup into variables • Simple display logic (item/items) • No parsing/eval and text automatically html encoded - no xss • Up to you how to separate your concerns!
  • 25. Angular… <ul ng-repeat="task in tasks"}><li ng-bind="task"></li></ul> <ng-pluralize count="personCount" when="{'0': 'Nobody is viewing.', 'one': '1 person is viewing.', 'other': '{} people are viewing.'}"> </ng-pluralize> <div ng-if="conference === 'dddperth'">Hi DDD Perth</div>
  • 26. React's design Our intellectual powers are rather geared to master static relations and that our powers to visualise processes evolving in time are relatively poorly developed. For that reason we should do (as wise programmers aware of our limitations) our utmost to shorten the conceptual gap between the static program and the dynamic process, to make the correspondence between the program (spread out in text space) and the process (spread out in time) as trivial as possible. - Dijkstra From <https://en.wikiquote.org/wiki/Edsger_W._Dijkstra>
  • 27. React's design Our intellectual powers are rather geared to master static relations and that our powers to visualise processes evolving in time are relatively poorly developed. For that reason we should do (as wise programmers aware of our limitations) our utmost to shorten the conceptual gap between the static program and the dynamic process, to make the correspondence between the program (spread out in text space) and the process (spread out in time) as trivial as possible. - Dijkstra From <https://en.wikiquote.org/wiki/Edsger_W._Dijkstra>
  • 28. React's design Application State render() Rendered Application Event (DOM, Push Messaging etc) Event Handler New State
  • 29. Virtual DOM <ul> <li key="1">Task 1</li> <li key="2">Task 2</li> </ul> <ul> <li key="1">Task 1</li> <li key="2">Task 2</li> <li key="3">Task 3</li> </ul> PATCH: Insert <li key="3">Task 3</li> at end of <ul> Delete li with key "1" <ul> <li key="2">Task 2</li> <li key="3">Task 3</li> </ul> <ul> <li key="2">Task 2</li> <li key="3">Task 3</li> </ul>
  • 30. Virtual DOM != Shadow DOM • <input id="foo" type="range"> • It renders a complex control • foo.childElement === null • CSS can be scoped to that Shadow DOM
  • 31. Breaking React down We can actually cover the entire library surface in 10 minutes.. Try doing that with angular/ember
  • 33. Anatomy of a React Component Lets code a simple React component
  • 34. Lifecycle of a React Component
  • 39. Styles render() { return ( <div> <span style={{color: 'red'}} className="myClass">text</a> </div> ) }
  • 40. Styles render() { var red = {color: 'red'} var classes = classNames(['classOne', something ? 'classTwo' : null]) return ( <div> <span style={red} className={classes}>text</a> </div> ) }
  • 41. Styles import myStyles from './component.less' render() {return ( <div> <span className={myStyle.someClass}>text</a> </div> ) }
  • 42. Isomorphic • The same React components can render on the server AND on the client • When client initialises, it: • attaches to the server generated dom • Generates the initial Virtual DOM from that • Renders a complete new VDOM • Brings server generated DOM up to date
  • 43. Testing • Shallow Rendering • Render into DOM • Test tools available
  • 44. Show me something decent Ok.. Here is Reactive Trader

Editor's Notes

  1. February this year a conference got organised for the first time called Code on the Sea (wear t-shirt). It was a two day conference held on the two sea days to and from the Bahamas on a 5 day cruise. One of the speakers who I have had the pleasure of having quite a few chats on the subject of web development was Rob Ashton.
  2. This guy, he is responsible for such blog posts as
  3. He likes to think of himself as a professional troll,
  4. but he has been talking about how to build front end web applications for quite a while now and has tried a lot of different approaches. His presentation was how he builds web applications at the moment, a large part of that was React. He has been using it for quite a while and built some sizable apps with a lot of success. After his presentation and a few follow up conversations I was keen to give React a solid go. But first, history of Web UI's
  5. DOM has different events/functions per browser Different browsers implement different apis Verbose Unstructured
  6. Handling onload Browser agnostic APIs Unstructured Unobtrusive javascript movement
  7. Loses focus/scroll position etc Causes unneeded DOM thrashing State no longer in the DOM
  8. Efficient DOM updates Need event subscriptions to each model Need event subscript to each element applyBindings is applied to State not in DOM No lost focus/scroll position etc
  9. Directives Attach behaviour to any html element Declarative Digest loop can be slow WebComponents Attach behaviour to any html element Declarative Encapsulates js/styles/html in a single scoped component
  10. Presentation is partly in html or a templating language backed by some javascript which provides the data Some approaches are cleaner and faster with less downsides, but the approaches really just are evolutions of the previous generation
  11. We will break this down later! But this is out task list in a single React component.
  12. Well, it's not actually HTML. It's something called JSX and JSX is this kind of weird!
  13. Views and ViewModels are tightly coupled, depending on how powerful your templating language is you put more and more computed information into your viewmodels for your view. Most changes in templates also require changes to the viewmodel unless it is purely styling. By not forcing you to separate your markup and display logic you can actually separate concerns properly.
  14. This quote by Dijkstra has been used quite a few times by the facebook team.
  15. This quote basically is saying we have a hard time visualising state changes over time and what that does to an application. React's approach is to make your application a giant idempotent function, which takes the application state in and the entire rendered output is produced. This makes react incredibly simple to reason about and is the reason it can scale so well to large projects, the design keeps complexity at bay.
  16. Who has used MVC? React's design takes inspiration from how easy it is to build server side applications. A request comes in, you build your model, you pass it to your ASP or Razor template which spits out the rendered page which is returned to the client. Application state can be immutable (and should be) and be the minimum amount of possible state to represent your application, anything that can be derived should be derived from the state in the render function.
  17. - React has a small api surface area - It is often described as the V in MVC/MVVM - but it doesn't need the other parts!! - I can use React with backbone or ampersand models, or anything I want really. NPM has hundreds and thousands of modules, react lets you pick and choose the ones you want - Enables building JavaScript applications, not angular or ember applications. Most application/all domain specific code is *not* coupled to React, just like in MVVM.
  18. Black - App Green - Add Task Purple - TasksList Blue - TaskItem But those components do not need to be for tasks, you can create abstract list components, then have task components which compose the abstract components
  19. Next is how do you pass data into your component.
  20. First thing is props
  21. Pretty simple so far? But what about internal state for a component?
  22. Next up we want to transition the internal state, so we need to react to things happening in the DOM
  23. Lets split this class so we can see everything on a single slide still
  24. Lets split this class so we can see everything on a single slide still
  25. Lets split this class so we can see everything on a single slide still
  26. First thing is props