SlideShare a Scribd company logo
You can find link to animated version
on last page
ABOUT USABOUT US
- finds leads from social media in
real-time
LeadScanr
Front-End, MLFull stack
Ievgen TerpilVyacheslav Pytel
@JenyaTerpil@vyacheslav_de
CHAPTER 0CHAPTER 0
INTROINTRO
INITIAL POINTINITIAL POINT
- Framework without improvements
- File structure
- Scalability
- Build tools
IDEAL APPIDEAL APP
- framework with community
- easy to implement new features
- easy to support
- easy to test
- localization
- build tools
CHAPTER 1CHAPTER 1
HYPEHYPE
FLUXFLUX
REDUXREDUX
@dan_abramov React Europe
REDUXREDUX
(state, action) => state
REDUXREDUX
REDUXREDUX
{
type: 'DEPOSIT',
value: 10
}
ACTIONACTION
REDUXREDUX
function counter(state = 0, action) {
switch (action.type) {
case 'DEPOSIT':
return state + action.value
case 'WITHDRAW':
return state - action.value
default:
return state
}
}
REDUCERREDUCER
Changes are made with pure functions
REDUXREDUX
STATESTATE
state tree
Single source of truth
REDUXREDUX
const store =
createStore(reducer, initialState)
store.subscribe(render)
// -----------------------------------
store.dispatch(action)
STORESTORE
State is read-only
REDUXREDUX
const App = ({ state }) => {
<div>
Balance: {state}
</div>
}
VIEWVIEW
VIEW LAYERVIEW LAYER
redux
react-redux ng-redux ........
REACT AS VIEW LAYERREACT AS VIEW LAYER
REACT AS VIEW LAYERREACT AS VIEW LAYER
Account = ({ balance, onDepositClick }) => {
<div>
<button onClick={onDepositClick}>
deposit
</button>
<div>Balance: {balance}</div>
</div>
}
REACT AS VIEW LAYERREACT AS VIEW LAYER
react-redux
connect(
mapStateToProps,
mapDispatchToProps
)(Account)
function mapStateToProps(state, ownProps) {
return { balance: state.balance }
}
function mapDispatchToProps(dispatch) {
return {
onDepositClick: () => dispatch(deposit())
}
}
REACT AS VIEW LAYERREACT AS VIEW LAYER
@connect(({ Subscriptions, Profile }) => ({
currentPlan: Subscriptions.get('currentPlan'),
userName: Profile.get('userName')
}))
export default class Subscriptions extends React.Component {
static propTypes = {
dispatch: PropTypes.func.isRequired,
userName: PropTypes.string,
currentPlan: PropTypes.object
}
...
}
our case with ES7
decorator
DUMB AND SMARTDUMB AND SMART
Dumb (Presentational)
Presentational and Container Components
Smart (Container)
real view
uses only props
DOM markup and styles
functional components
logic
Redux's connect
binds cb for dumb
DOM markup and styles
reusable
your mini Bootstrap
SIDE EFFECTSSIDE EFFECTS
SIDE EFFECTSSIDE EFFECTS
SIDE EFFECTS - BASE APPROACHSIDE EFFECTS - BASE APPROACH
{ type: 'FETCH_ACCOUNT_REQUEST' }
{ type: 'FETCH_ACCOUNT_SUCCESS', account: { ... } }
{ type: 'FETCH_ACCOUNT_FAILURE', error: 'Oops' }
function receiveAccount(account) {
return {
type: FETCH_ACCOUNT_SUCCESS,
account
}
}
actions
action creators
SIDE EFFECTS - BASE APPROACHSIDE EFFECTS - BASE APPROACH
redux-thunk
let getAccount = id => dispatch => {
dispatch(requestAccount(id));
return fetch('/account', id)
.then(account => dispatch(receiveAccount(account)))
.catch(error => dispatch(throwError(error)));
};
complex action creator
API request
redux-api-middleware
import { CALL_API } from `redux-api-middleware`;
{
[CALL_API]: {
endpoint: 'api/account',
method: 'GET',
types: ['REQUEST', 'SUCCESS', 'FAILURE']
}
}
action creators
SIDE EFFECTS -SIDE EFFECTS - LESS BOILERPLATELESS BOILERPLATE
declarative
SIDE EFFECTS -SIDE EFFECTS - LESS BOILERPLATELESS BOILERPLATE
CHAPTER 2CHAPTER 2
PRODUCTIONPRODUCTION
FEATURE FOLDERSFEATURE FOLDERS
FEATURE FOLDERSFEATURE FOLDERS
view actions reducers
i
i
i
feature1
feature2
feature3
FEATURE FOLDERSFEATURE FOLDERS
view actions reducers
i
i
i
feature1
feature2
feature3
set of standart components
FEATURE FOLDERSFEATURE FOLDERS
view actions reducers
i
i
i
feature1
feature2
feature3
set of standart components
main reducer
FEATURE FOLDERSFEATURE FOLDERS
view actions reducers
i
i
i
feature1
feature2
feature3
set of standart components
main reducer
all actions
FEATURE FOLDERSFEATURE FOLDERS
our solutions
import-glob
import reducers from './features/**/reducers.js';
generator-redux-component
yo redux-component
import actions from './features/**/actions.js';
account/
Account.js
x
actions.js
reducres.js
button/
Button.jsx
b-button.scss
Smart (feature) Dump
redux-promise - if it receives a promise, it will dispatch the resolved
value of the promise
export function getAccount() {
return async (api) => {
return {
type: events.ACCOUNT_READY,
account: await api.options.account.get()
};
};
}
our case with ES7
SIDE EFFECTS -SIDE EFFECTS - ADVANCED USAGEADVANCED USAGE
Action Creator
Service 1
Service 2
Service 3
A
A
A
SIDE EFFECTS -SIDE EFFECTS - ADVANCED USAGEADVANCED USAGE
Action Creator
Service 1
Service 2
Service 3
A
A
A
SIDE EFFECTS -SIDE EFFECTS - ADVANCED USAGEADVANCED USAGE
Action Creator
Action Creator
SIDE EFFECTS -SIDE EFFECTS - ADVANCED USAGEADVANCED USAGE
applyMiddlewares(middleware1, middleware2, ...)
redux-chain-middleware
dispatch([
startProcessCard(),
setCreditCard(card),
getOffers(),
buy(plan.get('id')),
pushState(null, '/account', {})
]);
async waterfall
SIDE EFFECTS -SIDE EFFECTS - ADVANCED USAGEADVANCED USAGE
CHAPTER 3CHAPTER 3
SAGASAGA
SAGASAGA
orchestrating complex/asynchronous operations
Saga
Service 1
Service 2
Service 3
REDUX-SAGAREDUX-SAGA
Generator functions (ES6) as action creators1
function* fetchAccount() {
const account = yield Api.fetch('/account')
console.log(account)
}
function* watchFetchAccount() {
yield* takeEvery('ACCOUNT_REQUESTED', fetchAccount)
}
REDUX-SAGAREDUX-SAGA
Declarative Effects
{
CALL: {
fn: Api.fetch,
args: ['./account']
}
}
2
yield only a description of
the function invocation
import { call } from 'redux-saga/effects'
function* fetchAccount() {
const account = yield call(Api.fetch, '/account')
// ...
}
- making our code testable
import { call, put } from 'redux-saga/effects'
function* fetchAccount() {
const account = yield call(Api.fetch, '/account')
yield put({ type: 'ACCOUNT_RECEIVED', products })
}
REDUX-SAGAREDUX-SAGA
Dispatching actions
import { call } from 'redux-saga/effects'
function* fetchAccount(dispatch) {
const account = yield call(Api.fetch, '/account')
dispatch({ type: 'ACCOUNT_RECEIVED', account })
}
assert.deepEqual(
iterator.next().value,
call(Api.fetch, '/account')
)
REDUX-SAGAREDUX-SAGA
Testing
const iterator = fetchAccount()
// create a fake response
const account = { balance: 10 }
// expects a dispatch instruction
assert.deepEqual(
iterator.next(account).value,
put({ type: 'ACCOUNT_RECEIVED', account })
)}
REDUX-SAGA APIREDUX-SAGA API
takeEvery
takeLatest
Saga
take put
call
A
Api
Dispatcher
fork
Saga
cancel
CONCLUSIONCONCLUSION
flux redux
redux: (state, action) => state
CONCLUSIONCONCLUSION
flux redux
redux: (state, action) => state
use feature folders
create collection of Dumb components
side-effects:
easy complex
redux-thunk
redux-promise
redux-saga
i
THANK YOU FOR YOURTHANK YOU FOR YOUR
ATTENTIONATTENTION
Ievgen TerpilVyacheslav Pytel
@JenyaTerpil@vyacheslav_de
Slawaq terpiljenya
LeadScanr
You can find animated version here

More Related Content

What's hot

Evan Schultz - Angular Camp - ng2-redux
Evan Schultz - Angular Camp - ng2-reduxEvan Schultz - Angular Camp - ng2-redux
Evan Schultz - Angular Camp - ng2-redux
Evan Schultz
 
Creating the interfaces of the future with the APIs of today
Creating the interfaces of the future with the APIs of todayCreating the interfaces of the future with the APIs of today
Creating the interfaces of the future with the APIs of today
gerbille
 

What's hot (20)

Http Communication in Angular 2.0
Http Communication in Angular 2.0Http Communication in Angular 2.0
Http Communication in Angular 2.0
 
Redux in Angular2 for jsbe
Redux in Angular2 for jsbeRedux in Angular2 for jsbe
Redux in Angular2 for jsbe
 
Modules and injector
Modules and injectorModules and injector
Modules and injector
 
Promises are so passé - Tim Perry - Codemotion Milan 2016
Promises are so passé - Tim Perry - Codemotion Milan 2016Promises are so passé - Tim Perry - Codemotion Milan 2016
Promises are so passé - Tim Perry - Codemotion Milan 2016
 
Redux pattens - JSHeroes 2018
Redux pattens - JSHeroes 2018Redux pattens - JSHeroes 2018
Redux pattens - JSHeroes 2018
 
Workshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & ReduxWorkshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & Redux
 
Workshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte IIWorkshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte II
 
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
 
Workshop 25: React Native - Components
Workshop 25: React Native - ComponentsWorkshop 25: React Native - Components
Workshop 25: React Native - Components
 
Workshop 17: EmberJS parte II
Workshop 17: EmberJS parte IIWorkshop 17: EmberJS parte II
Workshop 17: EmberJS parte II
 
AngularJS - Services
AngularJS - ServicesAngularJS - Services
AngularJS - Services
 
Evan Schultz - Angular Camp - ng2-redux
Evan Schultz - Angular Camp - ng2-reduxEvan Schultz - Angular Camp - ng2-redux
Evan Schultz - Angular Camp - ng2-redux
 
Enterprise State Management with NGRX/platform
Enterprise State Management with NGRX/platformEnterprise State Management with NGRX/platform
Enterprise State Management with NGRX/platform
 
Workshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte IIIWorkshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte III
 
Introduction to hexagonal architecture
Introduction to hexagonal architectureIntroduction to hexagonal architecture
Introduction to hexagonal architecture
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS Directives
 
Drupal8Day: Demystifying Drupal 8 Ajax Callback commands
Drupal8Day: Demystifying Drupal 8 Ajax Callback commandsDrupal8Day: Demystifying Drupal 8 Ajax Callback commands
Drupal8Day: Demystifying Drupal 8 Ajax Callback commands
 
Creating the interfaces of the future with the APIs of today
Creating the interfaces of the future with the APIs of todayCreating the interfaces of the future with the APIs of today
Creating the interfaces of the future with the APIs of today
 
Demystifying AJAX Callback Commands in Drupal 8
Demystifying AJAX Callback Commands in Drupal 8Demystifying AJAX Callback Commands in Drupal 8
Demystifying AJAX Callback Commands in Drupal 8
 
Workshop 22: React-Redux Middleware
Workshop 22: React-Redux MiddlewareWorkshop 22: React-Redux Middleware
Workshop 22: React-Redux Middleware
 

Viewers also liked

CHARYASS PHARMACY PROFILE 2
CHARYASS PHARMACY PROFILE 2CHARYASS PHARMACY PROFILE 2
CHARYASS PHARMACY PROFILE 2
Charles Nkrumah
 
Ash and Lacy SA Spacer Support System 12pp Email Version
Ash and Lacy SA Spacer Support System 12pp Email VersionAsh and Lacy SA Spacer Support System 12pp Email Version
Ash and Lacy SA Spacer Support System 12pp Email Version
Dion Marsh
 
Tableau-Salesforce_Topic3_Embed in Context
Tableau-Salesforce_Topic3_Embed in ContextTableau-Salesforce_Topic3_Embed in Context
Tableau-Salesforce_Topic3_Embed in Context
Mathieu Emanuelli
 
ESOS Assessment Presentation
ESOS Assessment PresentationESOS Assessment Presentation
ESOS Assessment Presentation
Samuel Cutler
 
Bishop_SpeedofLight_Final
Bishop_SpeedofLight_FinalBishop_SpeedofLight_Final
Bishop_SpeedofLight_Final
Clayton Bishop
 
LOOKBOOK 1 COMPLETE
LOOKBOOK 1 COMPLETELOOKBOOK 1 COMPLETE
LOOKBOOK 1 COMPLETE
Jessica Rowe
 

Viewers also liked (16)

Redux and redux saga
Redux and redux sagaRedux and redux saga
Redux and redux saga
 
The redux saga begins
The redux saga beginsThe redux saga begins
The redux saga begins
 
역시 Redux
역시 Redux역시 Redux
역시 Redux
 
ASHSCREEN
ASHSCREENASHSCREEN
ASHSCREEN
 
Basic electronics
Basic electronicsBasic electronics
Basic electronics
 
Morse et al 2012
Morse et al 2012Morse et al 2012
Morse et al 2012
 
CHARYASS PHARMACY PROFILE 2
CHARYASS PHARMACY PROFILE 2CHARYASS PHARMACY PROFILE 2
CHARYASS PHARMACY PROFILE 2
 
Ash and Lacy SA Spacer Support System 12pp Email Version
Ash and Lacy SA Spacer Support System 12pp Email VersionAsh and Lacy SA Spacer Support System 12pp Email Version
Ash and Lacy SA Spacer Support System 12pp Email Version
 
Kickboxing
KickboxingKickboxing
Kickboxing
 
Final3
Final3Final3
Final3
 
Tableau-Salesforce_Topic3_Embed in Context
Tableau-Salesforce_Topic3_Embed in ContextTableau-Salesforce_Topic3_Embed in Context
Tableau-Salesforce_Topic3_Embed in Context
 
Steel
SteelSteel
Steel
 
ESOS Assessment Presentation
ESOS Assessment PresentationESOS Assessment Presentation
ESOS Assessment Presentation
 
Bishop_SpeedofLight_Final
Bishop_SpeedofLight_FinalBishop_SpeedofLight_Final
Bishop_SpeedofLight_Final
 
Mahmoud_Emera_CV
Mahmoud_Emera_CVMahmoud_Emera_CV
Mahmoud_Emera_CV
 
LOOKBOOK 1 COMPLETE
LOOKBOOK 1 COMPLETELOOKBOOK 1 COMPLETE
LOOKBOOK 1 COMPLETE
 

Similar to Redux. From twitter hype to production

Redux. From twitter hype to production
Redux. From twitter hype to productionRedux. From twitter hype to production
Redux. From twitter hype to production
FDConf
 
Reactive.architecture.with.Angular
Reactive.architecture.with.AngularReactive.architecture.with.Angular
Reactive.architecture.with.Angular
Evan Schultz
 
Dynamics ax 2012 workflow development
Dynamics ax 2012 workflow development Dynamics ax 2012 workflow development
Dynamics ax 2012 workflow development
Ahmed Farag
 

Similar to Redux. From twitter hype to production (20)

Redux. From twitter hype to production
Redux. From twitter hype to productionRedux. From twitter hype to production
Redux. From twitter hype to production
 
The evolution of redux action creators
The evolution of redux action creatorsThe evolution of redux action creators
The evolution of redux action creators
 
Prescribing RX Responsibly
Prescribing RX ResponsiblyPrescribing RX Responsibly
Prescribing RX Responsibly
 
Dropwizard Introduction
Dropwizard IntroductionDropwizard Introduction
Dropwizard Introduction
 
React & Redux
React & ReduxReact & Redux
React & Redux
 
Jsf intro
Jsf introJsf intro
Jsf intro
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API's
 
Dependency injection - the right way
Dependency injection - the right wayDependency injection - the right way
Dependency injection - the right way
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
 
Reactive.architecture.with.Angular
Reactive.architecture.with.AngularReactive.architecture.with.Angular
Reactive.architecture.with.Angular
 
Dynamics ax 2012 workflow development
Dynamics ax 2012 workflow development Dynamics ax 2012 workflow development
Dynamics ax 2012 workflow development
 
Redux training
Redux trainingRedux training
Redux training
 
Advanced RESTful Rails
Advanced RESTful RailsAdvanced RESTful Rails
Advanced RESTful Rails
 
Advanced RESTful Rails
Advanced RESTful RailsAdvanced RESTful Rails
Advanced RESTful Rails
 
Battle of React State Managers in frontend applications
Battle of React State Managers in frontend applicationsBattle of React State Managers in frontend applications
Battle of React State Managers in frontend applications
 
Let's react - Meetup
Let's react - MeetupLet's react - Meetup
Let's react - Meetup
 
Maintaining sanity in a large redux app
Maintaining sanity in a large redux appMaintaining sanity in a large redux app
Maintaining sanity in a large redux app
 
angular fundamentals.pdf
angular fundamentals.pdfangular fundamentals.pdf
angular fundamentals.pdf
 
React lecture
React lectureReact lecture
React lecture
 
Beginner’s tutorial (part 2) how to integrate redux-saga in react native app
Beginner’s tutorial (part 2) how to integrate redux-saga in react native appBeginner’s tutorial (part 2) how to integrate redux-saga in react native app
Beginner’s tutorial (part 2) how to integrate redux-saga in react native app
 

Recently uploaded

Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 

Recently uploaded (20)

IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Introduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationIntroduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG Evaluation
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT Professionals
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 

Redux. From twitter hype to production