ReactJs Presentation
ReactJs Presentation
Andrew Hull
@aghull
normative.com
React First Impressions
React First Impressions
React First Impressions
WT
F?
!
“Reaction” to React
“Reaction” to React
“Ugly.”
“Reaction” to React
“Ugly.”
“Separation of concerns!!”
“Reaction” to React
“Ugly.”
“Separation of concerns!!”
• Don’t sweat it
“Reaction” to React
• Don’t sweat it
• JSX
“Reaction” to React
• Don’t sweat it
• JSX
• It’s actually just Javascript
“Reaction” to React
• Don’t sweat it
• JSX
• It’s actually just Javascript
• It’s not a templating language
“Reaction” to React
• Don’t sweat it
• JSX
• It’s actually just Javascript
• It’s not a templating language
• If you don’t like it, you don’t hafta
React Second Impressions
React Second Impressions
Just
React has no…
… controllers
… directives
… templates
… global event listeners
… models
… no view models
Just Components
“Separation of concerns!!”
“Separation
“Do you even
of concerns!!”
MVC?”
What if we “separate” another way?
What if we “separate” another way?
CartComponent
What if we “separate” another way?
CartComponent
CartListComponent
What if we “separate” another way?
CartComponent
CartListComponent
CartItemComponent
What if we “separate” another way?
CartComponent
CartListComponent
CartItemComponent
ButtonComponent
Separation of
Concerns Components
Separation of
Concerns Components
•composable
Separation of
Concerns Components
•composable
•reusable
Separation of
Concerns Components
•composable
•reusable
•maintainable
Separation of
Concerns Components
•composable
•reusable
•maintainable
•testable
Separation of
Concerns Components
•composable
•reusable
•maintainable
•testable
Backbone: Pub-sub
item.on('change:name', function() {…
Traditional data flows
No framework: Any component can
communicate with any other component
Backbone: Pub-sub
item.on('change:name', function() {…
Backbone: Pub-sub
item.on('change:name', function() {…
props.
check.
Props accessed on this.props
Props accessed on this.props
props.
Props accessed on this.props
props.
Props accessed on this.props
props.
props.
Props accessed on this.props
props.
props.
Props are immutable
Props are immutable
props.
Props are immutable
props.
Props are immutable
Don’t touch
my stuff!
props.
State is mutable
props.
State is mutable
props.
State is mutable
props.
State is mutable
Whatever you
say, dude.
props.
State can become props
State can become props
props.
State can become props
props.
State can become props
props.
props.
State can become props
props.
props.
Data only flows one way
Data only flows one way
CartItemComponent
<input>
Data flows down with handlers
CartComponent!
!
<CartListComponent!
list={this.state.list}!
onChange={this.handleChange}/>
Data flows down with handlers
CartComponent!
CartListComponent!
!
! <CartListComponent!
this.props.list.map(function(item) {!
list={this.state.list}!
<CartItemComponent item={item}!
onChange={this.handleChange}/>
onChange={this.props.onChange}/>!
})
Data flows down with handlers
CartComponent!
CartListComponent!
!
! <CartListComponent!
this.props.list.map(function(item) {!
list={this.state.list}!
<CartItemComponent item={item}!
onChange={this.handleChange}/>
onChange={this.props.onChange}/>!
})
CartItemComponent!
!
changeQty: function() {!
… does stuff!
this.props.onChange();!
}!
Data flows down with handlers
CartComponent!
CartListComponent!
!
! <CartListComponent!
this.props.list.map(function(item) {!
list={this.state.list}!
<CartItemComponent item={item}!
onChange={this.handleChange}/>
onChange={this.props.onChange}/>!
})
CartItemComponent!
!
changeQty: function() {!
… does stuff!
this.props.onChange();!
}!
• It’s inconsistent
Touching the DOM is evil
• It’s inconsistent
• It’s hard to test
Touching the DOM is evil
• It’s inconsistent
• It’s hard to test
• It’s brittle
Touching the DOM is evil
• It’s inconsistent
• It’s hard to test
• It’s brittle
• It’s EXPENSIVE!
Back to JSX
JSX Compiled
It’s just Javascript
It’s just Javascript
Why learn yet another
template language?
What’s actually happening
in render() ?
What’s actually happening
in render() ?
Lifecycle Method
… Except when it doesn’t
How do I access the actual DOM?
How do I know when render() is done?
Lifecycle Method
wut.
Declarative Templates suck!
wut.
Declarative Templates suck!
Sounds legit!
wut.
Why all this is awesome
Why all this is awesome
• One-way data flow keeps complexity
under control
Why all this is awesome
• One-way data flow keeps complexity
under control
• Easy to debug self-contained
components
Why all this is awesome
• One-way data flow keeps complexity
under control
• Easy to debug self-contained
components
• Library doesn’t dictate too much
Why all this is awesome
• One-way data flow keeps complexity
under control
• Easy to debug self-contained
components
• Library doesn’t dictate too much
• Ridiculous potential
A small demo
http://www.emergent.info/iphone-hairgate
Where to go from here?
Where to go from here?