SlideShare uma empresa Scribd logo
1 de 108
Baixar para ler offline
Why React matters
Credits: lifehack.org
ShihChi
Huang
learn once
write anywhere
web developer
web developer
mobile developer
What’s React
A javascript
library for
building UI
A javascript
library for
building UI
javascript
A javascript
library for
building UI
javascript
UI
var Greeting = React.createClass({
render() {
return (
<p>{"HELLO " + this.props.name}</p>
);
}
});
<Greeting name="techplanet" />
// HELLO techplanet
against best practices
worst technology ever*
ridicolousback
90s
WTF
against best practices
worst technology ever*
ridicolousback
90s
WTF
Credits: vjeux@
min(Time to Find Root Cause)
M C
V
UNIX Philosophy
do one thing and do it well
UNIX Philosophy
do one thing and do it well
UNIX Philosophy
write programs to work together
do one thing and do it well
UNIX Philosophy
write programs to work together
handle text streams
Separation
of
Concerns
shouldComponentUpdate
shouldComponentUpdate
render
true
ES2015
warm-up
function hello() {
return 'world';
}
// arrow function
var hello = () => {
return 'world';
}
var hello = () => ‘world';
function hello() {
return 'world';
}
// arrow function
var hello = () => {
return 'world';
}
var hello = () => ‘world';
function hello() {
return 'world';
}
// arrow function
var hello = () => {
return 'world';
}
function hello() {
return 'world';
}
// arrow function
var hello = () => {
return 'world';
}
var hello = () => ‘world';
function hello() {
return 'world';
}
// arrow function
var hello = () => {
return 'world';
}
// arrow function
var hello = () => {
return 'world';
}
var hello = () => ‘world';
var state = {
foo: foo,
bar: bar,
}
var state = {
foo: foo,
bar: bar,
}
var state = {
foo: foo,
bar: bar,
}
// enhanced object literals
var state = {
};
var state = {
foo: foo,
bar: bar,
}
var state = {
foo: foo,
bar: bar,
}
// enhanced object literals
var state = {
};
var state = {
foo: foo,
bar: bar,
}
// enhanced object literals
var state = {
foo,
};
var state = {
foo: foo,
bar: bar,
}
var state = {
foo: foo,
bar: bar,
}
// enhanced object literals
var state = {
};
var state = {
foo: foo,
bar: bar,
}
// enhanced object literals
var state = {
foo,
};
var state = {
foo: foo,
bar: bar,
}
// enhanced object literals
var state = {
foo,
bar,
};
var Greet = React.createClass({
render() {
return <div />;
}
});
// class
class Greet extends React.Component {
render() {
return <div />;
}
}
var PropTypes = React.PropTypes;
var Components = React.Components;
// destructuring
var { PropTypes, Component } = React;
var PropTypes = React.PropTypes;
var Components = React.Components;
// destructuring
var { PropTypes, Component } = React;
var PropTypes = React.PropTypes;
var Components = React.Components;
// destructuring
var { PropTypes, Component } = React;
var PropTypes = React.PropTypes;
var Components = React.Components;
// destructuring
var { PropTypes, Component } = React;
var PropTypes = React.PropTypes;
var Components = React.Components;
// destructuring
var { PropTypes, Component } = React;
var PropTypes = React.PropTypes;
var Components = React.Components;
// destructuring
var { PropTypes, Component } = React;
var todos = this.props.todos.map(todo =>
<TodoItem
/>
});
var todos = this.props.todos.map(todo =>
<TodoItem
/>
});
var todos = this.props.todos.map(todo =>
<TodoItem
id={todo.id}
/>
});
var todos = this.props.todos.map(todo =>
<TodoItem
/>
});
var todos = this.props.todos.map(todo =>
<TodoItem
id={todo.id}
/>
});
var todos = this.props.todos.map(todo =>
<TodoItem
id={todo.id}
content={todo.content}
/>
});
var todos = this.props.todos.map(todo =>
<TodoItem
/>
});
var todos = this.props.todos.map(todo =>
<TodoItem
id={todo.id}
/>
});
var todos = this.props.todos.map(todo =>
<TodoItem
id={todo.id}
content={todo.content}
/>
});
var todos = this.props.todos.map(todo =>
<TodoItem
id={todo.id}
content={todo.content}
isCompleted={todo.isCompleted}
/>
});
var todos = this.props.todos.map(todo =>
<TodoItem
/>
});
var todos = this.props.todos.map(todo =>
<TodoItem
id={todo.id}
/>
});
var todos = this.props.todos.map(todo =>
<TodoItem
id={todo.id}
content={todo.content}
/>
});
var todos = this.props.todos.map(todo =>
<TodoItem
id={todo.id}
content={todo.content}
isCompleted={todo.isCompleted}
/>
});
var todos = this.props.todos.map(todo =>
<TodoItem
id={todo.id}
content={todo.content}
isCompleted={todo.isCompleted}
/>
});
// spread operator
var todos = this.props.todos.map(todo =>
<TodoItem {...todo} />
});
var data = {
foo: 'bar',
hello: 'world',
answer: 42,
};
var data = {
foo: 'bar',
hello: 'world',
answer: 42,
};
var { foo, ...rest } = data;
var data = {
foo: 'bar',
hello: 'world',
answer: 42,
};
var { foo, ...rest } = data;
// rest
{
hello: 'world',
answer: 42
}
// arrow function
var hello = () => ‘world’;
// enhanced object literal
var state = { foo, bar };
// destructuring
var { PropTypes, Component } = React;
// class
class Greet extends React.Component {}
// spread operator
<TodoItem {...todo} />
Are you still watchingthere?
Continue
Back
UI = f(state)
pure function
is a function where
the return value is only
determined by its input values
// f(x) = x + 1;
var increment = (x) => {
return x + 1;
}
// f(x) = 2^x * x^3 - x - 1;
var complex = (x) => {
return Math.pow(2, x)
* Math.pow(x, 3)
- x - 1;
}
pure function
is a function where
the return value is only
determined by its input values
at any given time
var counter = 0;
setInterval(() => counter++, 1000);
var timeVariant = (x) => {
return x + counter;
}
> timeVariant(3)
> 4
// after few seconds
> timeVariant(3)
> 7
Predictable
class TodoApp extends React.Component {
render() {
var { isLoaded, todos } = this.props;
if (!isLoaded) { return <Spinner />; }
if (!todos.length) {
return <EmptyResult />;
}
return (
<TodoList>
{this.props.todos.map(todo => {
return <TodoItem {...todo} />;
})}
</TodoList>
);
}
}
class TodoApp extends React.Component {
render() {
var { isLoaded, todos } = this.props;
if (!isLoaded) { return <Spinner />; }
if (!todos.length) {
return <EmptyResult />;
}
return (
<TodoList>
{this.props.todos.map(todo => {
return <TodoItem {...todo} />;
})}
</TodoList>
);
}
}
class TodoApp extends React.Component {
render() {
var { isLoaded, todos } = this.props;
if (!isLoaded) { return <Spinner />; }
if (!todos.length) {
return <EmptyResult />;
}
return (
<TodoList>
{this.props.todos.map(todo => {
return <TodoItem {...todo} />;
})}
</TodoList>
);
}
}
class TodoApp extends React.Component {
render() {
var { isLoaded, todos } = this.props;
if (!isLoaded) { return <Spinner />; }
if (!todos.length) {
return <EmptyResult />;
}
return (
<TodoList>
{this.props.todos.map(todo => {
return <TodoItem {...todo} />;
})}
</TodoList>
);
}
}
class TodoApp extends React.Component {
render() {
var { isLoaded, todos } = this.props;
if (!isLoaded) { return <Spinner />; }
if (!todos.length) {
return <EmptyResult />;
}
return (
<TodoList>
{this.props.todos.map(todo => {
return <TodoItem {...todo} />;
})}
</TodoList>
);
}
}
class TodoApp extends React.Component {
render() {
var { isLoaded, todos } = this.props;
if (!isLoaded) { return <Spinner />; }
if (!todos.length) {
return <EmptyResult />;
}
return (
<TodoList>
{this.props.todos.map(todo => {
return <TodoItem {...todo} />;
})}
</TodoList>
);
}
}
class TodoApp extends React.Component {
render() {
var { isLoaded, todos } = this.props;
if (!isLoaded) { return <Spinner />; }
if (!todos.length) {
return <EmptyResult />;
}
return (
<TodoList>
{this.props.todos.map(todo => {
return <TodoItem {...todo} />;
})}
</TodoList>
);
}
}
class TodoApp extends React.Component {
render() {
var { isLoaded, todos } = this.props;
if (!isLoaded) { return <Spinner />; }
if (!todos.length) {
return <EmptyResult />;
}
return (
<TodoList>
{this.props.todos.map(todo => {
return <TodoItem {...todo} />;
})}
</TodoList>
);
}
}
class TodoApp extends React.Component {
render() {
var { isLoaded, todos } = this.props;
if (!isLoaded) { return <Spinner />; }
if (!todos.length) {
return <EmptyResult />;
}
return (
<TodoList>
{this.props.todos.map(todo => {
return <TodoItem {...todo} />;
})}
</TodoList>
);
}
}
class TodoApp extends React.Component {
render() {
var { isLoaded, todos } = this.props;
if (!isLoaded) { return <Spinner />; }
if (!todos.length) {
return <EmptyResult />;
}
return (
<TodoList>
{this.props.todos.map(todo => {
return <TodoItem {...todo} />;
})}
</TodoList>
);
}
}
class TodoApp extends React.Component {
render() {
var { isLoaded, todos } = this.props;
if (!isLoaded) { return <Spinner />; }
if (!todos.length) {
return <EmptyResult />;
}
return (
<TodoList>
{this.props.todos.map(todo => {
return <TodoItem {...todo} />;
})}
</TodoList>
);
}
}
class TodoApp extends React.Component {
render() {
var { isLoaded, todos } = this.props;
if (!isLoaded) { return <Spinner />; }
if (!todos.length) {
return <EmptyResult />;
}
return (
<TodoList>
{this.props.todos.map(todo => {
return <TodoItem {...todo} />;
})}
</TodoList>
);
}
}
class TodoApp extends React.Component {
render() {
var { isLoaded, todos } = this.props;
if (!isLoaded) { return <Spinner />; }
if (!todos.length) {
return <EmptyResult />;
}
return (
<TodoList>
{this.props.todos.map(todo => {
return <TodoItem {...todo} />;
})}
</TodoList>
);
}
}
class TodoApp extends React.Component {
render() {
var { isLoaded, todos } = this.props;
if (!isLoaded) { return <Spinner />; }
if (!todos.length) {
return <EmptyResult />;
}
return (
<TodoList>
{this.props.todos.map(todo => {
return <TodoItem {...todo} />;
})}
</TodoList>
);
}
}
class TodoApp extends React.Component {
render() {
var { isLoaded, todos } = this.props;
if (!isLoaded) { return <Spinner />; }
if (!todos.length) {
return <EmptyResult />;
}
return (
<TodoList>
{this.props.todos.map(todo => {
return <TodoItem {...todo} />;
})}
</TodoList>
);
}
}
UX
simple ≠ familiar
credits: facebook.github.io/flux
scalable?
View
Store Dispatcher
Action
View
Store Dispatcher
Action
Unidirectional
re-render
whenever
state changes
re-render
whenever
state changes
re-render
whenever
state changes
computation
intensive?
Immutable!
get a new value
whenever make a change
credits: David Nolen
linked list
X
linked list
XY
linked list
XY
Z
linked list
XY
Z
structure sharing
linked list
structure sharing
structure sharing
• space efficiency
structure sharing
• computation efficiency
• space efficiency
class TodoItem extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
}
render() {
// ...
}
}
class TodoItem extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
}
render() {
// ...
}
}
class TodoItem extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
var { content, isCompleted } = this.props;
}
render() {
// ...
}
}
class TodoItem extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
}
render() {
// ...
}
}
class TodoItem extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
var { content, isCompleted } = this.props;
}
render() {
// ...
}
}
class TodoItem extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
var { content, isCompleted } = this.props;
return (
content !== nextProps.content &&
isCompleted !== nextProps.isCompleted
);
}
render() {
// ...
}
}
class TodoItem extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
}
render() {
// ...
}
}
class TodoItem extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
var { content, isCompleted } = this.props;
}
render() {
// ...
}
}
class TodoItem extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
var { content, isCompleted } = this.props;
return (
content !== nextProps.content &&
isCompleted !== nextProps.isCompleted
);
}
render() {
// ...
}
}
class TodoItem extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
var { content, isCompleted } = this.props;
return (
this.props === nextProps
);
}
render() {
// ...
}
}
class TodoItem extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
}
render() {
// ...
}
}
class TodoItem extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
var { content, isCompleted } = this.props;
}
render() {
// ...
}
}
class TodoItem extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
var { content, isCompleted } = this.props;
return (
content !== nextProps.content &&
isCompleted !== nextProps.isCompleted
);
}
render() {
// ...
}
}
class TodoItem extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
var { content, isCompleted } = this.props;
return (
this.props === nextProps
);
}
render() {
// ...
}
}
class TodoItem extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
}
render() {
// ...
}
}
class TodoItem extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
var { content, isCompleted } = this.props;
}
render() {
// ...
}
}
class TodoItem extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
var { content, isCompleted } = this.props;
return (
content !== nextProps.content &&
isCompleted !== nextProps.isCompleted
);
}
render() {
// ...
}
}
class TodoItem extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
var { content, isCompleted } = this.props;
return (
this.props === nextProps
);
}
render() {
// ...
}
}
pros / nextProps are mutable and we
can’t simply
compare it’s reference
var Immutable = require('immutable');
var Immutable = require('immutable');var Immutable = require('immutable');
var todo = Immutable.Map({
content: 'say hello',
isCompleted: false
});
var Immutable = require('immutable');var Immutable = require('immutable');
var todo = Immutable.Map({
content: 'say hello',
isCompleted: false
});
var Immutable = require('immutable');
var todo = Immutable.Map({
content: 'say hello',
isCompleted: false
});
var mutatedTodo = todo.set(
“isCompleted”, true
);
var Immutable = require('immutable');var Immutable = require('immutable');
var todo = Immutable.Map({
content: 'say hello',
isCompleted: false
});
var Immutable = require('immutable');
var todo = Immutable.Map({
content: 'say hello',
isCompleted: false
});
var mutatedTodo = todo.set(
“isCompleted”, true
);
var Immutable = require('immutable');
var todo = Immutable.Map({
content: 'say hello',
isCompleted: false
});
var mutatedTodo = todo.set(
“isCompleted”, true
);
if (todo !== mutatedTodo) {
console.log('changed!');
// > changed!
}
class TodoItem extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
return (
this.props === nextProps
);
}
render() {
// ...
}
}
class TodoItem extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
return (
this.props === nextProps
);
}
render() {
// ...
}
}
recap
recap
• UI = f(state)
recap
• Predictable
• UI = f(state)
recap
• Predictable
• UI = f(state)
• Immutable
<Questions />

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Workshop 26: React Native - The Native Side
Workshop 26: React Native - The Native SideWorkshop 26: React Native - The Native Side
Workshop 26: React Native - The Native Side
 
Rxjs marble-testing
Rxjs marble-testingRxjs marble-testing
Rxjs marble-testing
 
Connecting your phone and home with firebase and android things - James Cogga...
Connecting your phone and home with firebase and android things - James Cogga...Connecting your phone and home with firebase and android things - James Cogga...
Connecting your phone and home with firebase and android things - James Cogga...
 
Quick start with React | DreamLab Academy #2
Quick start with React | DreamLab Academy #2Quick start with React | DreamLab Academy #2
Quick start with React | DreamLab Academy #2
 
Sane Sharding with Akka Cluster
Sane Sharding with Akka ClusterSane Sharding with Akka Cluster
Sane Sharding with Akka Cluster
 
Migrating from Flux to Redux. Why and how.
Migrating from Flux to Redux. Why and how.Migrating from Flux to Redux. Why and how.
Migrating from Flux to Redux. Why and how.
 
Kotlin delegates in practice - Kotlin Everywhere Stockholm
Kotlin delegates in practice - Kotlin Everywhere StockholmKotlin delegates in practice - Kotlin Everywhere Stockholm
Kotlin delegates in practice - Kotlin Everywhere Stockholm
 
Kotlin Delegates in practice - Kotlin community conf
Kotlin Delegates in practice - Kotlin community confKotlin Delegates in practice - Kotlin community conf
Kotlin Delegates in practice - Kotlin community conf
 
Java9 Beyond Modularity - Java 9 más allá de la modularidad
Java9 Beyond Modularity - Java 9 más allá de la modularidadJava9 Beyond Modularity - Java 9 más allá de la modularidad
Java9 Beyond Modularity - Java 9 más allá de la modularidad
 
Architectures in the compose world
Architectures in the compose worldArchitectures in the compose world
Architectures in the compose world
 
Redux saga: managing your side effects. Also: generators in es6
Redux saga: managing your side effects. Also: generators in es6Redux saga: managing your side effects. Also: generators in es6
Redux saga: managing your side effects. Also: generators in es6
 
What's in Kotlin for us - Alexandre Greschon, MyHeritage
What's in Kotlin for us - Alexandre Greschon, MyHeritageWhat's in Kotlin for us - Alexandre Greschon, MyHeritage
What's in Kotlin for us - Alexandre Greschon, MyHeritage
 
Managing parallelism using coroutines
Managing parallelism using coroutinesManaging parallelism using coroutines
Managing parallelism using coroutines
 
Kotlin Generation
Kotlin GenerationKotlin Generation
Kotlin Generation
 
Akka Typed (quick talk) - JFokus 2018
Akka Typed (quick talk) - JFokus 2018Akka Typed (quick talk) - JFokus 2018
Akka Typed (quick talk) - JFokus 2018
 
Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3 Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3
 
Promise: async programming hero
Promise: async programming heroPromise: async programming hero
Promise: async programming hero
 
The redux saga begins
The redux saga beginsThe redux saga begins
The redux saga begins
 
How do we use hooks
How do we use hooksHow do we use hooks
How do we use hooks
 
Asynchronous CompletableFuture Presentation by László-Róbert Albert @Crossover
Asynchronous CompletableFuture Presentation by László-Róbert Albert @CrossoverAsynchronous CompletableFuture Presentation by László-Róbert Albert @Crossover
Asynchronous CompletableFuture Presentation by László-Róbert Albert @Crossover
 

Destaque

A month by month guide to On Hold Marketing for Restaurants and Hospitality.
A month by month guide to On Hold Marketing for Restaurants and Hospitality.A month by month guide to On Hold Marketing for Restaurants and Hospitality.
A month by month guide to On Hold Marketing for Restaurants and Hospitality.
Advitel_crow_greencm15
 
Google blogger 教學
Google blogger 教學Google blogger 教學
Google blogger 教學
鈺棠 徐
 
Passing The Joel Test In The PHP World
Passing The Joel Test In The PHP WorldPassing The Joel Test In The PHP World
Passing The Joel Test In The PHP World
Lorna Mitchell
 

Destaque (12)

Introducing PostCSS
Introducing PostCSSIntroducing PostCSS
Introducing PostCSS
 
A month by month guide to On Hold Marketing for Restaurants and Hospitality.
A month by month guide to On Hold Marketing for Restaurants and Hospitality.A month by month guide to On Hold Marketing for Restaurants and Hospitality.
A month by month guide to On Hold Marketing for Restaurants and Hospitality.
 
Linux 教育訓練
Linux 教育訓練Linux 教育訓練
Linux 教育訓練
 
Google blogger 教學
Google blogger 教學Google blogger 教學
Google blogger 教學
 
CSS入門教學
CSS入門教學CSS入門教學
CSS入門教學
 
jQuery入門
jQuery入門jQuery入門
jQuery入門
 
Passing The Joel Test In The PHP World
Passing The Joel Test In The PHP WorldPassing The Joel Test In The PHP World
Passing The Joel Test In The PHP World
 
PHPUnit best practices presentation
PHPUnit best practices presentationPHPUnit best practices presentation
PHPUnit best practices presentation
 
The road to php 7.1
The road to php 7.1The road to php 7.1
The road to php 7.1
 
JavaScript/CSS 2015 Autumn
JavaScript/CSS 2015 AutumnJavaScript/CSS 2015 Autumn
JavaScript/CSS 2015 Autumn
 
Redis for the Everyday Developer
Redis for the Everyday DeveloperRedis for the Everyday Developer
Redis for the Everyday Developer
 
Redis in Practice
Redis in PracticeRedis in Practice
Redis in Practice
 

Semelhante a Why react matters

Semelhante a Why react matters (20)

Higher Order Components and Render Props
Higher Order Components and Render PropsHigher Order Components and Render Props
Higher Order Components and Render Props
 
Recompacting your react application
Recompacting your react applicationRecompacting your react application
Recompacting your react application
 
JS Fest 2019. Glenn Reyes. With great power comes great React hooks!
JS Fest 2019. Glenn Reyes. With great power comes great React hooks!JS Fest 2019. Glenn Reyes. With great power comes great React hooks!
JS Fest 2019. Glenn Reyes. With great power comes great React hooks!
 
React redux
React reduxReact redux
React redux
 
25-functions.ppt
25-functions.ppt25-functions.ppt
25-functions.ppt
 
Higher-Order Components — Ilya Gelman
Higher-Order Components — Ilya GelmanHigher-Order Components — Ilya Gelman
Higher-Order Components — Ilya Gelman
 
React JS Hooks Sheet .pdf
React JS Hooks Sheet .pdfReact JS Hooks Sheet .pdf
React JS Hooks Sheet .pdf
 
2018 05-16 Evolving Technologies: React, Babel & Webpack
2018 05-16 Evolving Technologies: React, Babel & Webpack2018 05-16 Evolving Technologies: React, Babel & Webpack
2018 05-16 Evolving Technologies: React, Babel & Webpack
 
Learning React: Facebook's Javascript Library For Building User Interfaces
Learning React: Facebook's Javascript Library For Building User InterfacesLearning React: Facebook's Javascript Library For Building User Interfaces
Learning React: Facebook's Javascript Library For Building User Interfaces
 
React 101
React 101React 101
React 101
 
React, Redux and es6/7
React, Redux and es6/7React, Redux and es6/7
React, Redux and es6/7
 
Chaining and function composition with lodash / underscore
Chaining and function composition with lodash / underscoreChaining and function composition with lodash / underscore
Chaining and function composition with lodash / underscore
 
Nevyn — Promise, It's Async! Swift Language User Group Lightning Talk 2015-09-24
Nevyn — Promise, It's Async! Swift Language User Group Lightning Talk 2015-09-24Nevyn — Promise, It's Async! Swift Language User Group Lightning Talk 2015-09-24
Nevyn — Promise, It's Async! Swift Language User Group Lightning Talk 2015-09-24
 
JSConf: All You Can Leet
JSConf: All You Can LeetJSConf: All You Can Leet
JSConf: All You Can Leet
 
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
 
Egghead redux-cheat-sheet-3-2-1
Egghead redux-cheat-sheet-3-2-1Egghead redux-cheat-sheet-3-2-1
Egghead redux-cheat-sheet-3-2-1
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Kitura Todolist tutorial
Kitura Todolist tutorialKitura Todolist tutorial
Kitura Todolist tutorial
 
Reactивная тяга
Reactивная тягаReactивная тяга
Reactивная тяга
 
Getting the Most Out of jQuery Widgets
Getting the Most Out of jQuery WidgetsGetting the Most Out of jQuery Widgets
Getting the Most Out of jQuery Widgets
 

Último

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Último (20)

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 

Why react matters

  • 3.
  • 5.
  • 6.
  • 8.
  • 11.
  • 12.
  • 17. var Greeting = React.createClass({ render() { return ( <p>{"HELLO " + this.props.name}</p> ); } }); <Greeting name="techplanet" /> // HELLO techplanet
  • 18.
  • 19. against best practices worst technology ever* ridicolousback 90s WTF
  • 20. against best practices worst technology ever* ridicolousback 90s WTF
  • 21. Credits: vjeux@ min(Time to Find Root Cause)
  • 22. M C V
  • 24. do one thing and do it well UNIX Philosophy
  • 25. do one thing and do it well UNIX Philosophy write programs to work together
  • 26. do one thing and do it well UNIX Philosophy write programs to work together handle text streams
  • 27.
  • 29.
  • 30.
  • 31.
  • 35. function hello() { return 'world'; } // arrow function var hello = () => { return 'world'; } var hello = () => ‘world';
  • 36. function hello() { return 'world'; } // arrow function var hello = () => { return 'world'; } var hello = () => ‘world'; function hello() { return 'world'; } // arrow function var hello = () => { return 'world'; }
  • 37. function hello() { return 'world'; } // arrow function var hello = () => { return 'world'; } var hello = () => ‘world'; function hello() { return 'world'; } // arrow function var hello = () => { return 'world'; } // arrow function var hello = () => { return 'world'; } var hello = () => ‘world';
  • 38. var state = { foo: foo, bar: bar, }
  • 39. var state = { foo: foo, bar: bar, } var state = { foo: foo, bar: bar, } // enhanced object literals var state = { };
  • 40. var state = { foo: foo, bar: bar, } var state = { foo: foo, bar: bar, } // enhanced object literals var state = { }; var state = { foo: foo, bar: bar, } // enhanced object literals var state = { foo, };
  • 41. var state = { foo: foo, bar: bar, } var state = { foo: foo, bar: bar, } // enhanced object literals var state = { }; var state = { foo: foo, bar: bar, } // enhanced object literals var state = { foo, }; var state = { foo: foo, bar: bar, } // enhanced object literals var state = { foo, bar, };
  • 42. var Greet = React.createClass({ render() { return <div />; } }); // class class Greet extends React.Component { render() { return <div />; } }
  • 43. var PropTypes = React.PropTypes; var Components = React.Components; // destructuring var { PropTypes, Component } = React;
  • 44. var PropTypes = React.PropTypes; var Components = React.Components; // destructuring var { PropTypes, Component } = React; var PropTypes = React.PropTypes; var Components = React.Components; // destructuring var { PropTypes, Component } = React;
  • 45. var PropTypes = React.PropTypes; var Components = React.Components; // destructuring var { PropTypes, Component } = React; var PropTypes = React.PropTypes; var Components = React.Components; // destructuring var { PropTypes, Component } = React; var PropTypes = React.PropTypes; var Components = React.Components; // destructuring var { PropTypes, Component } = React;
  • 46. var todos = this.props.todos.map(todo => <TodoItem /> });
  • 47. var todos = this.props.todos.map(todo => <TodoItem /> }); var todos = this.props.todos.map(todo => <TodoItem id={todo.id} /> });
  • 48. var todos = this.props.todos.map(todo => <TodoItem /> }); var todos = this.props.todos.map(todo => <TodoItem id={todo.id} /> }); var todos = this.props.todos.map(todo => <TodoItem id={todo.id} content={todo.content} /> });
  • 49. var todos = this.props.todos.map(todo => <TodoItem /> }); var todos = this.props.todos.map(todo => <TodoItem id={todo.id} /> }); var todos = this.props.todos.map(todo => <TodoItem id={todo.id} content={todo.content} /> }); var todos = this.props.todos.map(todo => <TodoItem id={todo.id} content={todo.content} isCompleted={todo.isCompleted} /> });
  • 50. var todos = this.props.todos.map(todo => <TodoItem /> }); var todos = this.props.todos.map(todo => <TodoItem id={todo.id} /> }); var todos = this.props.todos.map(todo => <TodoItem id={todo.id} content={todo.content} /> }); var todos = this.props.todos.map(todo => <TodoItem id={todo.id} content={todo.content} isCompleted={todo.isCompleted} /> }); var todos = this.props.todos.map(todo => <TodoItem id={todo.id} content={todo.content} isCompleted={todo.isCompleted} /> }); // spread operator var todos = this.props.todos.map(todo => <TodoItem {...todo} /> });
  • 51.
  • 52. var data = { foo: 'bar', hello: 'world', answer: 42, };
  • 53. var data = { foo: 'bar', hello: 'world', answer: 42, }; var { foo, ...rest } = data;
  • 54. var data = { foo: 'bar', hello: 'world', answer: 42, }; var { foo, ...rest } = data; // rest { hello: 'world', answer: 42 }
  • 55. // arrow function var hello = () => ‘world’; // enhanced object literal var state = { foo, bar }; // destructuring var { PropTypes, Component } = React; // class class Greet extends React.Component {} // spread operator <TodoItem {...todo} />
  • 56. Are you still watchingthere? Continue Back
  • 58. pure function is a function where the return value is only determined by its input values
  • 59. // f(x) = x + 1; var increment = (x) => { return x + 1; } // f(x) = 2^x * x^3 - x - 1; var complex = (x) => { return Math.pow(2, x) * Math.pow(x, 3) - x - 1; }
  • 60. pure function is a function where the return value is only determined by its input values at any given time
  • 61. var counter = 0; setInterval(() => counter++, 1000); var timeVariant = (x) => { return x + counter; } > timeVariant(3) > 4 // after few seconds > timeVariant(3) > 7
  • 63. class TodoApp extends React.Component { render() { var { isLoaded, todos } = this.props; if (!isLoaded) { return <Spinner />; } if (!todos.length) { return <EmptyResult />; } return ( <TodoList> {this.props.todos.map(todo => { return <TodoItem {...todo} />; })} </TodoList> ); } }
  • 64. class TodoApp extends React.Component { render() { var { isLoaded, todos } = this.props; if (!isLoaded) { return <Spinner />; } if (!todos.length) { return <EmptyResult />; } return ( <TodoList> {this.props.todos.map(todo => { return <TodoItem {...todo} />; })} </TodoList> ); } } class TodoApp extends React.Component { render() { var { isLoaded, todos } = this.props; if (!isLoaded) { return <Spinner />; } if (!todos.length) { return <EmptyResult />; } return ( <TodoList> {this.props.todos.map(todo => { return <TodoItem {...todo} />; })} </TodoList> ); } }
  • 65. class TodoApp extends React.Component { render() { var { isLoaded, todos } = this.props; if (!isLoaded) { return <Spinner />; } if (!todos.length) { return <EmptyResult />; } return ( <TodoList> {this.props.todos.map(todo => { return <TodoItem {...todo} />; })} </TodoList> ); } } class TodoApp extends React.Component { render() { var { isLoaded, todos } = this.props; if (!isLoaded) { return <Spinner />; } if (!todos.length) { return <EmptyResult />; } return ( <TodoList> {this.props.todos.map(todo => { return <TodoItem {...todo} />; })} </TodoList> ); } } class TodoApp extends React.Component { render() { var { isLoaded, todos } = this.props; if (!isLoaded) { return <Spinner />; } if (!todos.length) { return <EmptyResult />; } return ( <TodoList> {this.props.todos.map(todo => { return <TodoItem {...todo} />; })} </TodoList> ); } }
  • 66. class TodoApp extends React.Component { render() { var { isLoaded, todos } = this.props; if (!isLoaded) { return <Spinner />; } if (!todos.length) { return <EmptyResult />; } return ( <TodoList> {this.props.todos.map(todo => { return <TodoItem {...todo} />; })} </TodoList> ); } } class TodoApp extends React.Component { render() { var { isLoaded, todos } = this.props; if (!isLoaded) { return <Spinner />; } if (!todos.length) { return <EmptyResult />; } return ( <TodoList> {this.props.todos.map(todo => { return <TodoItem {...todo} />; })} </TodoList> ); } } class TodoApp extends React.Component { render() { var { isLoaded, todos } = this.props; if (!isLoaded) { return <Spinner />; } if (!todos.length) { return <EmptyResult />; } return ( <TodoList> {this.props.todos.map(todo => { return <TodoItem {...todo} />; })} </TodoList> ); } } class TodoApp extends React.Component { render() { var { isLoaded, todos } = this.props; if (!isLoaded) { return <Spinner />; } if (!todos.length) { return <EmptyResult />; } return ( <TodoList> {this.props.todos.map(todo => { return <TodoItem {...todo} />; })} </TodoList> ); } }
  • 67. class TodoApp extends React.Component { render() { var { isLoaded, todos } = this.props; if (!isLoaded) { return <Spinner />; } if (!todos.length) { return <EmptyResult />; } return ( <TodoList> {this.props.todos.map(todo => { return <TodoItem {...todo} />; })} </TodoList> ); } } class TodoApp extends React.Component { render() { var { isLoaded, todos } = this.props; if (!isLoaded) { return <Spinner />; } if (!todos.length) { return <EmptyResult />; } return ( <TodoList> {this.props.todos.map(todo => { return <TodoItem {...todo} />; })} </TodoList> ); } } class TodoApp extends React.Component { render() { var { isLoaded, todos } = this.props; if (!isLoaded) { return <Spinner />; } if (!todos.length) { return <EmptyResult />; } return ( <TodoList> {this.props.todos.map(todo => { return <TodoItem {...todo} />; })} </TodoList> ); } } class TodoApp extends React.Component { render() { var { isLoaded, todos } = this.props; if (!isLoaded) { return <Spinner />; } if (!todos.length) { return <EmptyResult />; } return ( <TodoList> {this.props.todos.map(todo => { return <TodoItem {...todo} />; })} </TodoList> ); } } class TodoApp extends React.Component { render() { var { isLoaded, todos } = this.props; if (!isLoaded) { return <Spinner />; } if (!todos.length) { return <EmptyResult />; } return ( <TodoList> {this.props.todos.map(todo => { return <TodoItem {...todo} />; })} </TodoList> ); } }
  • 68.
  • 69. UX
  • 70.
  • 77.
  • 82. get a new value whenever make a change
  • 91. structure sharing • computation efficiency • space efficiency
  • 92. class TodoItem extends React.Component { shouldComponentUpdate(nextProps, nextState) { } render() { // ... } }
  • 93. class TodoItem extends React.Component { shouldComponentUpdate(nextProps, nextState) { } render() { // ... } } class TodoItem extends React.Component { shouldComponentUpdate(nextProps, nextState) { var { content, isCompleted } = this.props; } render() { // ... } }
  • 94. class TodoItem extends React.Component { shouldComponentUpdate(nextProps, nextState) { } render() { // ... } } class TodoItem extends React.Component { shouldComponentUpdate(nextProps, nextState) { var { content, isCompleted } = this.props; } render() { // ... } } class TodoItem extends React.Component { shouldComponentUpdate(nextProps, nextState) { var { content, isCompleted } = this.props; return ( content !== nextProps.content && isCompleted !== nextProps.isCompleted ); } render() { // ... } }
  • 95. class TodoItem extends React.Component { shouldComponentUpdate(nextProps, nextState) { } render() { // ... } } class TodoItem extends React.Component { shouldComponentUpdate(nextProps, nextState) { var { content, isCompleted } = this.props; } render() { // ... } } class TodoItem extends React.Component { shouldComponentUpdate(nextProps, nextState) { var { content, isCompleted } = this.props; return ( content !== nextProps.content && isCompleted !== nextProps.isCompleted ); } render() { // ... } } class TodoItem extends React.Component { shouldComponentUpdate(nextProps, nextState) { var { content, isCompleted } = this.props; return ( this.props === nextProps ); } render() { // ... } }
  • 96. class TodoItem extends React.Component { shouldComponentUpdate(nextProps, nextState) { } render() { // ... } } class TodoItem extends React.Component { shouldComponentUpdate(nextProps, nextState) { var { content, isCompleted } = this.props; } render() { // ... } } class TodoItem extends React.Component { shouldComponentUpdate(nextProps, nextState) { var { content, isCompleted } = this.props; return ( content !== nextProps.content && isCompleted !== nextProps.isCompleted ); } render() { // ... } } class TodoItem extends React.Component { shouldComponentUpdate(nextProps, nextState) { var { content, isCompleted } = this.props; return ( this.props === nextProps ); } render() { // ... } }
  • 97. class TodoItem extends React.Component { shouldComponentUpdate(nextProps, nextState) { } render() { // ... } } class TodoItem extends React.Component { shouldComponentUpdate(nextProps, nextState) { var { content, isCompleted } = this.props; } render() { // ... } } class TodoItem extends React.Component { shouldComponentUpdate(nextProps, nextState) { var { content, isCompleted } = this.props; return ( content !== nextProps.content && isCompleted !== nextProps.isCompleted ); } render() { // ... } } class TodoItem extends React.Component { shouldComponentUpdate(nextProps, nextState) { var { content, isCompleted } = this.props; return ( this.props === nextProps ); } render() { // ... } } pros / nextProps are mutable and we can’t simply compare it’s reference
  • 98. var Immutable = require('immutable');
  • 99. var Immutable = require('immutable');var Immutable = require('immutable'); var todo = Immutable.Map({ content: 'say hello', isCompleted: false });
  • 100. var Immutable = require('immutable');var Immutable = require('immutable'); var todo = Immutable.Map({ content: 'say hello', isCompleted: false }); var Immutable = require('immutable'); var todo = Immutable.Map({ content: 'say hello', isCompleted: false }); var mutatedTodo = todo.set( “isCompleted”, true );
  • 101. var Immutable = require('immutable');var Immutable = require('immutable'); var todo = Immutable.Map({ content: 'say hello', isCompleted: false }); var Immutable = require('immutable'); var todo = Immutable.Map({ content: 'say hello', isCompleted: false }); var mutatedTodo = todo.set( “isCompleted”, true ); var Immutable = require('immutable'); var todo = Immutable.Map({ content: 'say hello', isCompleted: false }); var mutatedTodo = todo.set( “isCompleted”, true ); if (todo !== mutatedTodo) { console.log('changed!'); // > changed! }
  • 102. class TodoItem extends React.Component { shouldComponentUpdate(nextProps, nextState) { return ( this.props === nextProps ); } render() { // ... } }
  • 103. class TodoItem extends React.Component { shouldComponentUpdate(nextProps, nextState) { return ( this.props === nextProps ); } render() { // ... } }
  • 104. recap
  • 105. recap • UI = f(state)
  • 107. recap • Predictable • UI = f(state) • Immutable