SlideShare uma empresa Scribd logo
1 de 40
Road trip with Redux
Damian Kmiecik
3rd of April 2017, Warsaw
Agenda
1. Flux
2. Redux
3. Code!
4. Pros and cons
5. Redux DevTools
6. Alternatives
7. Links
1. Flux
Data Flow
Flux
[1]
Data Flow
Flux
[1]
Data Flow
Flux
Action as reaction on user interaction
[1]
Flux
Action
1. Trigger a dispatch to the
stores
2. Including payload of data
Flux
Dispacher
1. Central hub that manages all
data flow in the application.
2. Distributing the actions to the
stores
Flux
1. Contain the application state
and logic
2. Manage the state of many
objects
Store
Flux
View
1. Listen for events that are
broadcast by the stores
2. Requests the new data via to
stores’
3. Set received data to its own
state
4. Render view
2. Redux
Sounds familiar?
Redux
Redux vs Flux
Redux
[2]
Redux
Action
1. Action creator returns actions
2. Doesn’t dispatch actions
Redux
Reducer
1. Pure functions
2. Returns new state to the Store
from combination of state and
action
Redux
1. One single immutable State
2. Contains the application
State
Store
3. Code!
Yeah!
Code!
Redux
React
export function setRepoState (st) {
return {
type: constants.SET_REPO_STATE,
payload: {
state: st
}
}
}
Redux
React
const initialState = Immutable.Map()
export default function repo
(state = initialState, action) {
if (!action.payload || !action.type)
return state
switch (action.type) {
case constants.SET_REPO_STATE:
let newState = Object.assign
(new Immutable.Map, state)
return newState.set
('status, action.payload.state)
default:
return state
}
}
Redux
React
const router = routerMiddleware(hashHistory)
const enhancer =
applyMiddleware(thunk, router)
const rootReducer = combineReducers({
repo,
routing
})
export default function configureStore
(initialState) {
return createStore(
rootReducer,
initialState,
composeWithDevTools(enhancer)
)
}
Redux
React
const store = configureStore()
const history =
syncHistoryWithStore(hashHistory, store)
render(
<Provider store={store}>
<Router history={history}
routes={routes} />
</Provider>,
document.getElementById('app')
)
Redux
React
//Container
@connect(state => ({
repository: state.repo
}))
render () {
const { dispatch } = this.props
const actions =
bindActionCreators(repository, dispatch)
}
Redux
Angular JS
The same as in the React app 
Redux
Angular JS
//App Main Module
let app = angular.module('app', [
ngRedux,
uiRouter
])
.value('repoActions', repoActions)
.config(routerConfig)
.config(
['$ngReduxProvider',
$ngReduxProvider => {
$ngReduxProvider
.createStoreWith(rootReducer,
[thunk, createLogger()])
}])
Redux
AngularJS
//Container
const disconnect =
$ngRedux.connect(
state => ({
repo: state.repo
}),
repoActions)
((state, actions) => {
this.actions = actions
})
$scope.$on('$destroy', disconnect)
$ngRedux.subscribe(() => {
this.repoStatus = $ngRedux.getState()
.repo.get('status')
})
Redux
Angular 2
The same as in the React and AngularJS app 
Redux
Angular 2
export interface IAppState {
todo?: ITodoState;
}
export const rootReducer =
combineReducers<IAppState>({
todo: todoReducer,
router: routerReducer
});
Redux
Angular 2
//App Main Module
middleware.push(
createEpicMiddleware<Action>(
combineEpics.combine()));
this.ngRedux.configureStore(
rootReducer,
{ },
middleware,
[devTool.isEnabled() ?
devTool.enhancer() : f => f]
);
ngReduxRouter.initialize();
Redux
Angular 2
//Container
@Component({
selector: 'gp-repo-list-container',
template: `
<gp-repo-list [repoList]="repoList |
async"></gp-repo-list>
`
})
export class RepoListContainer {
@select(state => state.repo)
public repoList: Observable<Object>;
}
4. Pros and cons
Pros and cons
Pros:
1. Immutable state
2. Store contains whole state from the
application
3. Simply data flow
4. Total separation of data and presentation
5. Dumb components
6. Useful DevTools
Cons:
1. Not needed in all cases
2. Be aware of damages caused
by state mutations
5. Redux DevTools
What?
Redux DevTools
6. Alternatives
What should I choose? O,o
Alternatives
MobX
https://github.com/mobxjs/mobx
AltJS
http://alt.js.org/
7. Links
Try it out!
Links
The SAM Pattern:
http://sam.js.org/
Flux:
https://facebook.github.io/flux/
Redux:
http://redux.js.org/
Redux DevTools:
https://github.com/gaearon/redux-devtools
Code:
https://github.com/dkmiecik/gp-react-redux
https://github.com/dkmiecik/gp-angular-redux
https://github.com/dkmiecik/gp-angular2-redux
Sources
Links
[1] https://facebook.github.io/flux/docs/in-depth-overview.html#content
[2] https://www.slideshare.net/JonasOhlsson/using-redux
Thank You 
damian.kmiecik.90@gmail.com
https://github.com/dkmiecik

Mais conteúdo relacionado

Mais procurados

MVest Spring Job Execution
MVest Spring Job ExecutionMVest Spring Job Execution
MVest Spring Job Execution
Shraddha Bora
 
SH 1 - SES 6 - compass-tel-aviv-slides.pptx
SH 1 - SES 6 - compass-tel-aviv-slides.pptxSH 1 - SES 6 - compass-tel-aviv-slides.pptx
SH 1 - SES 6 - compass-tel-aviv-slides.pptx
MongoDB
 
ASP.NET MVC Controllers & Actions
ASP.NET MVC Controllers & ActionsASP.NET MVC Controllers & Actions
ASP.NET MVC Controllers & Actions
onsela
 

Mais procurados (20)

Reactивная тяга
Reactивная тягаReactивная тяга
Reactивная тяга
 
React state managmenet with Redux
React state managmenet with ReduxReact state managmenet with Redux
React state managmenet with Redux
 
MVest Spring Job Execution
MVest Spring Job ExecutionMVest Spring Job Execution
MVest Spring Job Execution
 
React redux
React reduxReact redux
React redux
 
SH 1 - SES 6 - compass-tel-aviv-slides.pptx
SH 1 - SES 6 - compass-tel-aviv-slides.pptxSH 1 - SES 6 - compass-tel-aviv-slides.pptx
SH 1 - SES 6 - compass-tel-aviv-slides.pptx
 
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
 
Introduction to react and redux
Introduction to react and reduxIntroduction to react and redux
Introduction to react and redux
 
React&redux
React&reduxReact&redux
React&redux
 
React 101
React 101React 101
React 101
 
React и redux
React и reduxReact и redux
React и redux
 
Hello, ReactorKit 
Hello, ReactorKit Hello, ReactorKit 
Hello, ReactorKit 
 
React, Redux, ES2015 by Max Petruck
React, Redux, ES2015   by Max PetruckReact, Redux, ES2015   by Max Petruck
React, Redux, ES2015 by Max Petruck
 
Building multi lingual and empatic bots - Sander van den Hoven - Codemotion A...
Building multi lingual and empatic bots - Sander van den Hoven - Codemotion A...Building multi lingual and empatic bots - Sander van den Hoven - Codemotion A...
Building multi lingual and empatic bots - Sander van den Hoven - Codemotion A...
 
React outbox
React outboxReact outbox
React outbox
 
Testowanie JavaScript
Testowanie JavaScriptTestowanie JavaScript
Testowanie JavaScript
 
Config/BuildConfig
Config/BuildConfigConfig/BuildConfig
Config/BuildConfig
 
Workshop 22: React-Redux Middleware
Workshop 22: React-Redux MiddlewareWorkshop 22: React-Redux Middleware
Workshop 22: React-Redux Middleware
 
Redux data flow with angular 2
Redux data flow with angular 2Redux data flow with angular 2
Redux data flow with angular 2
 
ASP.NET MVC Controllers & Actions
ASP.NET MVC Controllers & ActionsASP.NET MVC Controllers & Actions
ASP.NET MVC Controllers & Actions
 
React js use contexts and useContext hook
React js use contexts and useContext hookReact js use contexts and useContext hook
React js use contexts and useContext hook
 

Semelhante a Damian Kmiecik - Road trip with Redux

Semelhante a Damian Kmiecik - Road trip with Redux (20)

Getting started with Redux js
Getting started with Redux jsGetting started with Redux js
Getting started with Redux js
 
Academy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingAcademy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & Tooling
 
Modern Web Apps Development 101
Modern Web Apps Development 101Modern Web Apps Development 101
Modern Web Apps Development 101
 
downloads_introduction to redux.pptx
downloads_introduction to redux.pptxdownloads_introduction to redux.pptx
downloads_introduction to redux.pptx
 
Intro react js
Intro react jsIntro react js
Intro react js
 
Workshop 27: Isomorphic web apps with ReactJS
Workshop 27: Isomorphic web apps with ReactJSWorkshop 27: Isomorphic web apps with ReactJS
Workshop 27: Isomorphic web apps with ReactJS
 
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
 
Redux
ReduxRedux
Redux
 
Redux data flow with angular
Redux data flow with angularRedux data flow with angular
Redux data flow with angular
 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
 
Vuex
VuexVuex
Vuex
 
Flux architecture
Flux architectureFlux architecture
Flux architecture
 
ASP .net MVC
ASP .net MVCASP .net MVC
ASP .net MVC
 
Simple React Todo List
Simple React Todo ListSimple React Todo List
Simple React Todo List
 
Spfx with react redux
Spfx with react reduxSpfx with react redux
Spfx with react redux
 
Building Modern Web Applications using React and Redux
 Building Modern Web Applications using React and Redux Building Modern Web Applications using React and Redux
Building Modern Web Applications using React and Redux
 
From mvc to redux: 停看聽
From mvc to redux: 停看聽From mvc to redux: 停看聽
From mvc to redux: 停看聽
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 
Redux data flow with angular
Redux data flow with angularRedux data flow with angular
Redux data flow with angular
 
React lecture
React lectureReact lecture
React lecture
 

Último

Último (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

Damian Kmiecik - Road trip with Redux