SlideShare una empresa de Scribd logo
1 de 53
React.Redux.Real world.
Rostislav (BABO)
BABO
2
3
4
5
6
FRONTEND
7
Webpack
React, Redux
CSS Modules
8
React
9
Бесконечные списки
Screen gif
10
React-ingrid
11
Отображать только те элементы, которые умещаются на экране
Universal rendering
const html = ReactDOM.renderToString(<App data={data} />)
res.send(html)
12
Блокирующий вызов
Future
React-dom-stream
res.write(`<!DOCTYPE html>`)
const stream = ReactDOMStream.renderToStaticMarkup(<App data={data} />);
stream.pipe(res)
13
Redux
14
DevTools,
Logger,
Time travelling15
Простота
16
Redux
const reducer = (oldState = `FOO`, action) => {
switch(action.type) {
case `UPDATE_FOO`:
return `BAR`
}
return oldState
}
const store = createStore(reducer)
17
// подписаться на обновления
store.subscribe(() => {
assert.ok(store.getState() === `BAR`)
})
// передать изменения
store.dispatch({
type: `UPDATE_FOO`
})
// получить текущее состояние
assert.ok(store.getState() === `FOO`)
Tests
const reducer = (oldState, action) => {
switch(action.type) {
case `ACTION_TYPE`:
return action.payload
}
}
assert.ok(reducer(``, `BAR`) === `BAR`)
18
React + Redux
<Provider store={store}>
<ButtonContainer />
</Provider>
const Button = ({handleClick, title}) => (
<button onClick={handleClick}>{title}</button>
)
19
const mapStateToProps = state => ({
title: state.title
})
const mapDispatchToProps = dispatch => ({
handleClick: () => dispatch({
type: `CLICK`
})
})
const ButtonContainer = connect(mapStateToProps, mapDispatchToProps)(Button)
Immutable
20
spread...
const initialState = {
foo: `foo`,
bar: `bar`
}
const reducer = (state = initialState, action) => {
switch(action.type) {
case `UPDATE_BAR`:
return {
...state,
bar: `baz`
}
}
}
return {
...state,
we: {
...state.we,
must: {
...state.we.must,
go: {
...state.we.must.go,
deeper: action.payload
}
}
}
}
21
Immutable.js
return {
...state,
we: {
...state.we,
must: {
...state.we.must,
go: {
...state.we.must.go,
deeper: action.payload
}
}
}
}
return state.setIn([`we`, `must`, `go`, `deeper`], action.payload)
22
Immutable.js
const mapStateToProps = state => ({
foo: state.get(`foo`),
bar: state.get(`bar`),
...
})
import { Map } from 'immutable'
const map = Map({
foo: `bar`
})
const { foo } = map
assert.fails(foo === `bar`)
assert.ok(foo === undefined)
23
Seamless-immutable
import Immutable from 'seamless-immutable'
const map = Immutable({foo: `bar`})
const { foo } = map
assert.ok(foo === `bar`)
24
Object.freeze()
~5 KB
return state.setIn([`we`, `must`, `go`, `deeper`], action.payload)
Расчеты
25
26
Вычисления
const computeAction = data => {
const result = compute(data)
return {
type: `COMPUTE_ACTION`,
payload: result
}
}
27
Масштабирование
28
state
<Component1 ... />
<Component2 ... />
<Component3 ... />
<Component4 ... />
compute1
compute2
compute3
compute4
Вычисления
29
const mapStateToProps = state => ({
result: compute(state.data)
})
Мемоизация | Reselect
import { createSelector } from 'reselect'
const clustersSelector = createSelector(
state => state.points,
state => state.map.zoom,
(points, zoom) => calculateClusters(points, zoom)
)
30
Actions
31
Flux Standard Action
{
type: `DO_SOMETHING`,
payload: {
foo: `bar`
},
meta: {
foo: `bar`
}
}
32
{
type: `DO_SOMETHING`,
payload: new Error(),
error: true
}
Realtime
REALTIME gif
Синхронизация экранов
33
Plain object
34
store.dispatch(...)
store.dispatch(...)
store.dispatch(...)
store.dispatch(...)
SOCKETS
if(action.meta && action.meta.sync) {
sockets.emit(action)
}
thunk
const asyncAction = () => dispatch => {
dispatch({
type: `REQUEST`
})
fetch()
.then(() => dispatch({type: `REQUEST_SUCCESS`}))
.catch(() => dispatch({type: `REQUEST_ERROR`}))
}
35
thunk??
export const finallySend = () => (dispatch, getState) => {
const {phone, location, latlng, description, uploadId} = getState().toJS()
dispatch({
type: SEND_REQUEST
})
if (isEmpty(latlng)) {
if (!location) {
dispatch(sendResults({phone, location, description, uploadId}))
return dispatch(setStep(`done`))
}
geocodeLocation(location).then(payload => {
const {lat: photoLat, lng: photoLon} = payload
dispatch(sendResults({phone, location, description, uploadId, photoLat, photoLon}))
})
} else {
const {lat: photoLat, lng: photoLon} = latlng
dispatch(sendResults({phone, location, description, uploadId, photoLat, photoLon}))
}
dispatch(setStep(`done`))
}
36
tests?
scale?
SAGA
37
Sagas
38
ON_CLICK
REQUEST
REQUEST_SUCCESS
function* rootSaga() {
yield takeLatest(`CLICK`, request)
}
function* request() {
try {
yield put({type: `REQUEST`})
const payload = yield call(api.requestData)
yield put({type: `REQUEST_SUCCESS`, payload})
} catch(e) {
yield put({type: `REQUEST_ERROR`})
}
}
Тесты
const generator = request()
expect(generator.next().value).toEqual(put({type: `REQUEST`))
expect(generator.next().value).toEqual(call(api.requestData))
expect(generator.next(dummyResponse).value).toEqual(put({type: `REQUEST_SUCCESS`, payload}))
39
Изоляция
40
Проблема?
41
Component
Component
Component
Component
const componentReducer = (state, action) => {
...
case `CLICK`:
return state.set(`clicked`, true)
….
}
cobmineReducers({
component1: componentReducer,
component2: componentReducer
...
})
`CLICK`
Переиспользование компонент
class ReusableComponent extends Component {
constructor() {
this.state = {clicked: false}
}
handleOnClick() {
this.setState({
clicked: true
})
}
render() {
return <button onClick={this.handleOnClick} />
}
}
42
43
redux-state
connectState(
mapLocalStateToProps,
mapLocalDispatchToProps,
mergeProps,
componentReducer
)(Component)
44
import {reducer as states} from `redux-state`
combineReducers({
states,
...
})
redux-multireducer
45
Component
Component
Component
Component
cobmineReducers({
component: multireducer({
`component1`: componentReducer,
`component2`: componentReducer,
`component3`: componentReducer,
...
}),
...
})
`CLICK_reducerKey=component1`
`CLICK_reducerKey=component2`
`CLICK_reducerKey=component3`
saga?
ELM
architecture
46
47
ELM
Model
Update
Command
View
Modularity
REDUX
State
Reducer
Saga
Componet
???
48
Updater
Model
Command
View
elm
49
Parent
Child
Child
redux-elm
//parentUpdater
import { Updater } from 'redux-elm';
import childUpdater, { init as childInit } from './childUpdater'
export const init = () => Immutable({
child1: childInit(),
child2: childInit()
});
export default new Updater(init(), saga)
.case(`Child1`, (model, action) => childUpdater(model.child1, action))
.case(`Child2`, (model, action) => childUpdater(model.child2, action))
.toReducer();
50
redux-elm
//Parent
import { forwardTo, view } from 'redux-elm'
import ChildView from 'redux-elm'
export default view(({ model, dispatch }) => (
<div>
<ChildView model={model} dispatch={forwardTo(dispatch, `Child1`)} />
<ChildView model={model} dispatch={forwardTo(dispatch, `Child2`)} />
</div>
));
51
AMAZING REDUX
seamless-immutable/immutable.js
reselect
redux-saga
redux-elm
52
Спасибо за внимание!
53

Más contenido relacionado

La actualidad más candente

ヘルスケアサービスを実現する最新技術 〜HealthKit・GCP + Goの活用〜
ヘルスケアサービスを実現する最新技術  〜HealthKit・GCP + Goの活用〜ヘルスケアサービスを実現する最新技術  〜HealthKit・GCP + Goの活用〜
ヘルスケアサービスを実現する最新技術 〜HealthKit・GCP + Goの活用〜
DeNA
 

La actualidad más candente (19)

Bangun datar dan bangun ruang
Bangun datar dan bangun ruangBangun datar dan bangun ruang
Bangun datar dan bangun ruang
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Михаил Матросов, Повседневный С++: boost и STL
Михаил Матросов, Повседневный С++: boost и STLМихаил Матросов, Повседневный С++: boost и STL
Михаил Матросов, Повседневный С++: boost и STL
 
The Ring programming language version 1.8 book - Part 74 of 202
The Ring programming language version 1.8 book - Part 74 of 202The Ring programming language version 1.8 book - Part 74 of 202
The Ring programming language version 1.8 book - Part 74 of 202
 
662305 11
662305 11662305 11
662305 11
 
The Ring programming language version 1.8 book - Part 65 of 202
The Ring programming language version 1.8 book - Part 65 of 202The Ring programming language version 1.8 book - Part 65 of 202
The Ring programming language version 1.8 book - Part 65 of 202
 
The Ring programming language version 1.9 book - Part 64 of 210
The Ring programming language version 1.9 book - Part 64 of 210The Ring programming language version 1.9 book - Part 64 of 210
The Ring programming language version 1.9 book - Part 64 of 210
 
กลุ่ม6
กลุ่ม6กลุ่ม6
กลุ่ม6
 
Mutation Testing - Voxxed Days Bucharest 10.03.2017
Mutation Testing - Voxxed Days Bucharest 10.03.2017Mutation Testing - Voxxed Days Bucharest 10.03.2017
Mutation Testing - Voxxed Days Bucharest 10.03.2017
 
The Ring programming language version 1.7 book - Part 72 of 196
The Ring programming language version 1.7 book - Part 72 of 196The Ring programming language version 1.7 book - Part 72 of 196
The Ring programming language version 1.7 book - Part 72 of 196
 
OpenGL L06-Performance
OpenGL L06-PerformanceOpenGL L06-Performance
OpenGL L06-Performance
 
The Ring programming language version 1.8 book - Part 73 of 202
The Ring programming language version 1.8 book - Part 73 of 202The Ring programming language version 1.8 book - Part 73 of 202
The Ring programming language version 1.8 book - Part 73 of 202
 
OpenGL Starter L02
OpenGL Starter L02OpenGL Starter L02
OpenGL Starter L02
 
The Ring programming language version 1.5.4 book - Part 59 of 185
The Ring programming language version 1.5.4 book - Part 59 of 185The Ring programming language version 1.5.4 book - Part 59 of 185
The Ring programming language version 1.5.4 book - Part 59 of 185
 
ヘルスケアサービスを実現する最新技術 〜HealthKit・GCP + Goの活用〜
ヘルスケアサービスを実現する最新技術  〜HealthKit・GCP + Goの活用〜ヘルスケアサービスを実現する最新技術  〜HealthKit・GCP + Goの活用〜
ヘルスケアサービスを実現する最新技術 〜HealthKit・GCP + Goの活用〜
 
The Ring programming language version 1.6 book - Part 86 of 189
The Ring programming language version 1.6 book - Part 86 of 189The Ring programming language version 1.6 book - Part 86 of 189
The Ring programming language version 1.6 book - Part 86 of 189
 
The Ring programming language version 1.10 book - Part 68 of 212
The Ring programming language version 1.10 book - Part 68 of 212The Ring programming language version 1.10 book - Part 68 of 212
The Ring programming language version 1.10 book - Part 68 of 212
 
Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)
Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)
Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)
 
The Ring programming language version 1.5.1 book - Part 64 of 180
The Ring programming language version 1.5.1 book - Part 64 of 180The Ring programming language version 1.5.1 book - Part 64 of 180
The Ring programming language version 1.5.1 book - Part 64 of 180
 

Similar a React. Redux. Real world.

オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)
Takayuki Goto
 

Similar a React. Redux. Real world. (20)

Using Redux-Saga for Handling Side Effects
Using Redux-Saga for Handling Side EffectsUsing Redux-Saga for Handling Side Effects
Using Redux-Saga for Handling Side Effects
 
Side effects-con-redux
Side effects-con-reduxSide effects-con-redux
Side effects-con-redux
 
React, Redux and es6/7
React, Redux and es6/7React, Redux and es6/7
React, Redux and es6/7
 
Reactive Programming Patterns with RxSwift
Reactive Programming Patterns with RxSwiftReactive Programming Patterns with RxSwift
Reactive Programming Patterns with RxSwift
 
Bulding a reactive game engine with Spring 5 & Couchbase
Bulding a reactive game engine with Spring 5 & CouchbaseBulding a reactive game engine with Spring 5 & Couchbase
Bulding a reactive game engine with Spring 5 & Couchbase
 
[JEEConf-2017] RxJava as a key component in mature Big Data product
[JEEConf-2017] RxJava as a key component in mature Big Data product[JEEConf-2017] RxJava as a key component in mature Big Data product
[JEEConf-2017] RxJava as a key component in mature Big Data product
 
React redux
React reduxReact redux
React redux
 
The evolution of redux action creators
The evolution of redux action creatorsThe evolution of redux action creators
The evolution of redux action creators
 
W-JAX 09 - Lift
W-JAX 09 - LiftW-JAX 09 - Lift
W-JAX 09 - Lift
 
Compose Async with RxJS
Compose Async with RxJSCompose Async with RxJS
Compose Async with RxJS
 
PyconKR 2018 Deep dive into Coroutine
PyconKR 2018 Deep dive into CoroutinePyconKR 2018 Deep dive into Coroutine
PyconKR 2018 Deep dive into Coroutine
 
Redux for ReactJS Programmers
Redux for ReactJS ProgrammersRedux for ReactJS Programmers
Redux for ReactJS Programmers
 
Recoil at Codete Webinars #3
Recoil at Codete Webinars #3Recoil at Codete Webinars #3
Recoil at Codete Webinars #3
 
HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?
 
Job Queue in Golang
Job Queue in GolangJob Queue in Golang
Job Queue in Golang
 
G*ワークショップ in 仙台 Grails(とことん)入門
G*ワークショップ in 仙台 Grails(とことん)入門G*ワークショップ in 仙台 Grails(とことん)入門
G*ワークショップ in 仙台 Grails(とことん)入門
 
Prescribing RX Responsibly
Prescribing RX ResponsiblyPrescribing RX Responsibly
Prescribing RX Responsibly
 
オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)
 
ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015
 
Cycle.js: Functional and Reactive
Cycle.js: Functional and ReactiveCycle.js: Functional and Reactive
Cycle.js: Functional and Reactive
 

Último

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 

Último (20)

%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
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
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
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
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
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 🔝✔️✔️
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 

React. Redux. Real world.