SlideShare ist ein Scribd-Unternehmen logo
1 von 41
Advanced
Patterns in Redux
Nir Kaufman
Nir Kaufman
@nirkaufman
Principal Front-end consultant
Google Developer Expert
Worldwide speaker and trainer
Agenda
Programming with messages.
Learn new terms to describe our flow.
Patterns and ideas.
Open your mind :)
Read this: https://goo.gl/rvQTGV .
Back in time
1997
CD-ROM Included
https://goo.gl/ZcpHZt
C Q SCommand Query Separation
Command–query separation (CQS)
Every method should either be
a command that performs an action,
or a query that returns data to the
caller, but not both
- Meyer, Bertrand.
Command–query separation (CQS)
Every method should either be
a command that performs an action,
or a query that returns data to the
caller, but not both.
- Meyer, Bertrand.
Command–query separation (CQS)
Asking a question
should not change the answer.
“
- Meyer, Bertrand.
Command–query separation (CQS)
Commands
Change the state of a system,
but do not return a value.
- Martin Fowler.
Command–query separation (CQS)
Queries
Return a result and do not change
the observable state of the system.
- Martin Fowler.
Command–query separation (CQS)
Dispatcher StateCommands
Queries
Redux
UI StoreActions
Selectors
CQS & Redux
Separate methods that change
state from those that don't. 
2003
https://goo.gl/ZcpHZt
65 Messaging Patterns
Messaging Patterns
Middleware ReducerAction
Creator
Store
Action ProcessingConstruction
Redux
Middleware ReducerAction
Creator
Store
Action ProcessingConstruction
Side Effects
Middleware ReducerAction
Creator
Store
Action ProcessingConstruction
Action Construction
Action Categories
Events Command Document
Event
Notify of a change.
*more than one handler
{
type : APP_OFFLINE,
payload: data,
meta : {...}
}
Command
Invoke a procedure.
*one handler, expect a reply
{
type : GET_USER,
payload: data,
meta : {...}
}
Document
*no reply, one reducer
Transfer data.
{
type : PRODUCT,
payload: data,
meta : {...}
}
Routing Patterns
Filtering Mapping Splitter Aggregator
Routing Patterns
Filtering
if(action.type === GET_DATA) {
}
Routing Patterns
Mapping
if(action.type === GET_DATA) {
if(action.payload.force){
// decision based on content
}
}
Routing Patterns
Mapping
if(action.type === GET_DATA) {
if(process.env.dev){
// decision based on context
}
}
Routing Patterns
Splitter
if(action.type === GET_DATA) {
dispatch(API_REQUEST)
dispatch(APP_PENDING)
}
Transform Patterns
Enricher Normalizer Translator
Transform Patterns
Enricher
if(action.type === SUBMIT_ORDER) {
let action = {
...action,
created: new Date()
};
next(action)
}
Normalizer
if(action.type === API_SUCCESS) {
const users = action.payload.reduce(...);
next({ type: UPDATE_USERS, payload: users})
}
Transform Patterns
Translator
Transform Patterns
if(action.type === SHOW_LOADER) {
dispatch({type: TOGGLE_LOADER, payload: true})
}
if(action.type === HIDE_LOADER) {
dispatch({type: TOGGLE_LOADER, payload: false})
}
The real world
We want to keep it simple.
nirkaufman@gmail.com
ME.
@nirkaufman

Weitere ähnliche Inhalte

Mehr von Nir Kaufman

Mehr von Nir Kaufman (20)

Decorators in js
Decorators in jsDecorators in js
Decorators in js
 
Styling recipes for Angular components
Styling recipes for Angular componentsStyling recipes for Angular components
Styling recipes for Angular components
 
Introduction To Angular's reactive forms
Introduction To Angular's reactive formsIntroduction To Angular's reactive forms
Introduction To Angular's reactive forms
 
Webstorm
WebstormWebstorm
Webstorm
 
Redux with angular 2 - workshop 2016
Redux with angular 2 - workshop 2016Redux with angular 2 - workshop 2016
Redux with angular 2 - workshop 2016
 
Angular Pipes Workshop
Angular Pipes WorkshopAngular Pipes Workshop
Angular Pipes Workshop
 
Data Structures in javaScript 2015
Data Structures in javaScript 2015Data Structures in javaScript 2015
Data Structures in javaScript 2015
 
redux and angular - up and running
redux and angular - up and runningredux and angular - up and running
redux and angular - up and running
 
Angular redux
Angular reduxAngular redux
Angular redux
 
How Angular2 Can Improve Your AngularJS Apps Today!
How Angular2 Can Improve Your AngularJS Apps Today!How Angular2 Can Improve Your AngularJS Apps Today!
How Angular2 Can Improve Your AngularJS Apps Today!
 
Angular2 workshop
Angular2 workshopAngular2 workshop
Angular2 workshop
 
Solid angular
Solid angularSolid angular
Solid angular
 
Webpack and angularjs
Webpack and angularjsWebpack and angularjs
Webpack and angularjs
 
Angular2 - getting-ready
Angular2 - getting-ready Angular2 - getting-ready
Angular2 - getting-ready
 
Up & running with ECMAScript6
Up & running with ECMAScript6Up & running with ECMAScript6
Up & running with ECMAScript6
 
AngularJS performance & production tips
AngularJS performance & production tipsAngularJS performance & production tips
AngularJS performance & production tips
 
AngularJS - Services
AngularJS - ServicesAngularJS - Services
AngularJS - Services
 
Angular js - 10 reasons to choose angularjs
Angular js - 10 reasons to choose angularjs Angular js - 10 reasons to choose angularjs
Angular js - 10 reasons to choose angularjs
 
Angular js routing options
Angular js routing optionsAngular js routing options
Angular js routing options
 
Angularjs - Unit testing introduction
Angularjs - Unit testing introductionAngularjs - Unit testing introduction
Angularjs - Unit testing introduction
 

Kürzlich hochgeladen

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Kürzlich hochgeladen (20)

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
 
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
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
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...
 

Advanced Redux Patterns