SlideShare a Scribd company logo
1 of 47
React & Redux
Keep your head cool and focused, there’s a tons of stuff to see today
Cedric Hartland
A project we’re targeting
2017 cedric.hartland@gmail.com 2
React – a gentle introduction
Javascript library for building user interfaces
2017 cedric.hartland@gmail.com 3
React – a library that defines views through components
• In a declarative way
• Components means reusability close to object oriented paradigm
• Given an application state, renders some shadow DOM
application state are inputs named properties
• Business logic, state flow and DOM rendering are independent
• Optimized rendering engine actually inspired from game engines
• Little assumption on application structure can “easily” integrate with other technologies
• Can render on server side SEO please
What else ? Not so much more
2017 cedric.hartland@gmail.com 4
React – what’s actually good in it ?
• Components
• Enhanced reusability well, keep it generic if you plan on reusing… it’s all about OOP
• Rendering lifecycle with optimizations
• Basic type checking not so basic with propTypes
• Becomes powerful with ES6 and more it’s not react, it’s ES6
• Dependency management
• Uptaded syntax and language features
• Css inclusions
• Arguably JSX
• As opposed to string based templates
• Don’t blame too quick, tsx exists too
2017 cedric.hartland@gmail.com 5
React – first thing first: JSX
• Update to JS – ease the code readability for React
• Elements, expressions, functions, etc.
• CSS horror !! Js based CSS injection, good alternative with CSS imports/modular CSS
2017 cedric.hartland@gmail.com 6
React.createElement(
"div",
{ "class": "app-head" },
React.createElement("h1", null, "Portfolio Quality" ),
React.createElement(
Tiles,
{ color: "blue" },
React.createElement(Tile, { value: 2.8294564, title: "Total quality" }),
React.createElement(Tile, { value: 2.75189, title: "Security" }),
React.createElement(Tile, { value: 2.82154, title: "Robustness" }),
React.createElement(Tile, { value: 2.98678, title: "Efficiency" }),
React.createElement(Tile, { value: 2.74234, title: "Changeability" }),
React.createElement(Tile, { value: 2.76354, title: "Transferability" })
)
);
<div class="app-head" >
<h1>Portfolio Quality</h1>
<Tiles color="blue" >
<Tile value={2.8294564} title="Total quality" />
<Tile value={2.75189} title="Security" />
<Tile value={2.82154} title="Robustness" />
<Tile value={2.98678} title="Efficiency" />
<Tile value={2.74234} title="Changeability" />
<Tile value={2.76354} title="Transferability" />
</Tiles>
</div>
ES5 JSX
A (not so) simple component
2017 cedric.hartland@gmail.com 7
class Tile extends React.Component {
static propTypes = {
value: React.PropTypes.number,
title: React.PropTypes.string
};
render() {
return ( <div className="tile">
<div className="tile-header">{this.props.title}</div>
<div className="tile-value">{numeral(this.props.value).format('0.00')}</div>
</div>
);
}
}
Properties
types
JSX
declarations
Reusable class
or function
Optional
parenthesis
wrapping
Js Expressions
in brackets
Using this component
2017 cedric.hartland@gmail.com 8
<div className="tiles">
<Tile value={2.8294564} title="Total quality" />
<Tile value={2.75189} title="Security" />
…
</div>
<div className="tiles">
{data.map((sample, index) => {
return <Tile key={index} {...sample} />;
})}
</div>
Reuse
component as
an html
element
From
collection of
data to
collection of
components
Properties
passed explicitely
to the component
Properties are submitted
implicitely from object
Key is required for collections
So React can omptimize re-
rendering
Adding user interactions
2017 cedric.hartland@gmail.com 9
class Filter extends React.Component {
…
render() {
return (
<div className="filter-input">
<input
type="text"
value={this.props.filterText}
placeholder={this.props.placeholder}
onChange={this.props.handleFilter}
/>
</div>);
}
}
Beware,
binding to this
use ES6 !
Bind functions
to events
(re-)Rendering workflow
2017 cedric.hartland@gmail.com 10
A few words on performance
• Mounting (first render) is not cheap estimated x5 times slower than jquery
• Creation of shadow DOM
• Rendering of shadow DOM elements to actual DOM
• Updating state
1. Component properties (inputs) changes trigger re-rendering
comparing properties has negative impact on performance
2. Rendering creates a shadow DOM little impact on performance
3. Compare new shadow DOM to previous one negative impact on performance
4. Rendering of only differences to actual DOM strong positive impact on performance
• Optimize via shouldComponentUpdate
• Bring business logic and guess whether the component should call render at all
not rendering when data are not changing has positive impact on performance
2017 cedric.hartland@gmail.com 11
React
• A few words before moving to next topic…
• …just in case it was not that clear
• React is designed in a declarative way
• It can define it’s own internal state, but…
• ...most components should always return same content for given input and not have
internal state dumb components, pure components
• State only comes from data properties, state
• No more jquery, backbone or whatever rendering tweaks on user
interactions or from other sources
• A single DOM source of truth is the output of render function
• Application state only belong in data properties, state, dom reflects this
2017 cedric.hartland@gmail.com 12
React – dumb & smart components
• Application state is not held in component
• Many components are said to be dumb
• only display data
• Dispatch events from user actions
• Some smarter components
• Operate other components and user actions functions
• Some bind to data-source to manage application state updates
2017 cedric.hartland@gmail.com 13
Few words on i18n
• Available with key/value extractions package react-intl
• Turn
• Into
2017 cedric.hartland@gmail.com 14
<Filter filterText={this.props.applications.filter}
handleFilter={this.handleFilter}
placeholder='Search...' />
<Filter filterText={this.props.applications.filter}
handleFilter={this.handleFilter}
placeholder={<FormattedMessage
id="applications.filterMesssage"
defaultMessage="Search…" />
} />
Propose ID
and default
message
Work with
plurality and
variables
React & Redux
Rock & Roll
2017 cedric.hartland@gmail.com 15
Redux – what the flux ?
• Many frameworks and approaches follows MVC like patterns
• Model manages behavior and data
• View represent the display of the model in UI
• Controller takes user input, manipulates model and cause views to update
• MVC existed before I was born
and still exist so it is kind of a norm
• Bidirectional communications
→ causes cycles and
create high complexity
as met in AAD, AED, Highlight, etc.
where 1 data change causes given
views to render several times or
indefinitely due to side effects
2017 cedric.hartland@gmail.com 16
Redux – what the flux ?
• React consumes data and
produce DOM
React updates DOM when
data changes
• Need for a data-source
management workflow
• Single source of truth
• Whole application state in the
centralized data store
not hidden in DOM or other weird places
• Flux, the original worflow :
2017 cedric.hartland@gmail.com 17
Dispatcher
View Store
Action
Redux - workflow close to that of flux
• Motivation
• MVC makes it hard to understand & debug application
model update another model, then update a view that update a model, then…
• SPAs high complexity data, interactions, asynchronicity, routing, etc.
data mutation and asynchronicity makes it hard to reason about the application
• Core principles
• Single source of truth
• The state of application stored in single object tree in single data store
• State is read-only
• Changing state requires an action that describes operation
• Changes are made with pure functions
• New state is new object no mutations
2017 cedric.hartland@gmail.com 19
Redux – flux
• Store is defined through
• State
• Reducers state mutator functions
• Consumes current state
• Consumes actions operations that could update state
• Produces new state …or return the previous state if not changed
(state, action) → state’
• Reducers can be combined
• Divide & conquer
• Reducers have to be pure functions
• If states are different, their reference pointer are different
• Benefit from predictability and testability
• No need for deep object comparison through components lifecycle save on most expensive operation
2017 cedric.hartland@gmail.com 20
Actions
• Action basic structure
• Type e.g. APPLICATION_FETCH
• Payload e.g. { id: appId }
• Action creators
• Centralize business logic processing avoid diverging duplicates from discording places in code
• Delegate type ↔ payload construction from dedicated functions
• Actions payload processing is business logic related independent from data stores
and views
• Dispatching actions
• Enforce loose coupling of code parts
• Event based actions dispatching
• Enable middleware based payload consumption and/or transformation
2017 cedric.hartland@gmail.com 21
Redux – workflow
2017 cedric.hartland@gmail.com 22
Dispatcher
View Store
Action
Redux – workflow
2017 cedric.hartland@gmail.com 23
Dispatcher
View
Store
Action
Reducers
R
R
R
State
Redux – workflow
2017 cedric.hartland@gmail.com 24
Dispatcher
View
Store
Action
Reducers
R
R
R
State
middlewares
API
Logs
Delay actions
Loop actions
Crash report
…
Redux – workflow
2017 cedric.hartland@gmail.com 25
Dispatcher
View
Store
Action
Reducers
R
R
R
State
middlewares
API
Logs
Delay actions
Loop actions
Crash report
…
event
Redux – workflow
2017 cedric.hartland@gmail.com 26
Dispatcher
View
Store
Action
Reducers
R
R
R
State
middlewares
API
Logs
Delay actions
Loop actions
Crash report
…
action
Redux – workflow
2017 cedric.hartland@gmail.com 27
Dispatcher
View
Store
Action
Reducers
R
R
R
State
middlewares
API
Logs
Delay actions
Loop actions
Crash report
…
action
Redux – workflow
2017 cedric.hartland@gmail.com 28
Dispatcher
View
Store
Action
Reducers
R
R
R
State
middlewares
API
Logs
Delay actions
Loop actions
Crash report
…
state
action
Redux – workflow
2017 cedric.hartland@gmail.com 29
Dispatcher
View
Store
Action
Reducers
R
R
R
State
middlewares
API
Logs
Delay actions
Loop actions
Crash report
…
new state
Redux – workflow
2017 cedric.hartland@gmail.com 30
Dispatcher
View
Store
Action
Reducers
R
R
R
State
middlewares
API
Logs
Delay actions
Loop actions
Crash report
…
action
Redux – workflow
2017 cedric.hartland@gmail.com 31
Dispatcher
View
Store
Action
Reducers
R
R
R
State
middlewares
API
Logs
Delay actions
Loop actions
Crash report
…
action
Redux – workflow
2017 cedric.hartland@gmail.com 32
Dispatcher
View
Store
Action
Reducers
R
R
R
State
middlewares
API
Logs
Delay actions
Loop actions
Crash report
…
state
action
Redux – workflow
2017 cedric.hartland@gmail.com 33
Dispatcher
View
Store
Action
Reducers
R
R
R
State
middlewares
API
Logs
Delay actions
Loop actions
Crash report
…
new state
Rock & Roll
• React
• Render components
• Optimized rendering workflow
• Redux
• Optimize weak parts of react rendering
• Together
• Makes model – view transformations unidirectional
• Optimize on view rendering and data processing
“easier” to debug and understand + efficient rendering
2017 cedric.hartland@gmail.com 34
Application structure
• sources
⁄ api/ // contains url information (builders) to (RESTful) API resources
⁄ business/ // contains data description and manipulations (redux workflow)
⁄ components/ // contains React dumb components
⁄ containers/ // contains React smart components
⁄ core/ // general application configuration skeleton
⁄ index.html // SPA entry point
⁄ main.jsx // SPA code entry point
⁄ store.js // redux data store setup
2017 cedric.hartland@gmail.com 35
Business logic
• sources
⁄ …
⁄ business/
⁄ any-concept/
⁄ specs/ // tests for business files, may be flat to folder or in such subfolder
⁄ actions.js // action creators (business logic operations there)
⁄ constants.js* // reusable constants (e.g. action variables)
⁄ reducers.js // reducer functions
⁄ sagas.js* // sagas middleware operations
⁄ ..middleware.js // other possible middleware linked to business logic concept
⁄ …
Components with * are optional depending on context
2017 cedric.hartland@gmail.com 36
API ?
• Api lists / links API urls and querying of those it’s all about getting data
• Use of ES6 fetch
• Or use of frameworks or libraries such as axios…
2017 cedric.hartland@gmail.com 37
axios('REST/applications')
.then((response) => {
return response.data.applications;
}).catch((error) => {
throw error;
});
Sagas ?
• Operate side-effect operations
• asynchronous operations e.g. manage data fetch from server
• Cache accesses
• Rely on generator pattern from ES6
2017 cedric.hartland@gmail.com 38
function* sagas() {
yield put({type: 'APPLICATIONS_FETCH_PENDING'});
try {
yield fork (takeLatest, 'APPLICATIONS_FETCH', fetchApplications, ApiApplications);
}
catch (error) {
yield put({type: 'APPLICATIONS_FETCH_ERROR', payload: error});
}
}
Generator
function
Dispatch
actions
Back to
reducer
Wait for
command to
be done
before moving
to next one
Define
network reuse
policy
Almost done…
Build, enhanced development process and how to test
2017 cedric.hartland@gmail.com 39
Testing
• As usual,
• Need for unit tests mocha, jasmine, jed, enzyme, etc.
• Need for integration tests
• Selenium, Casperjs, Nightwatch, etc.
• Consider mock servers option
• Need for manual testing
• Again, consider mock server option
• Need to run tests on real browsers
Nothing really new out there
2017 cedric.hartland@gmail.com 40
Packaging
• Not so little development stack
• jsx/es6/es2016/…
• sass/less/modular (s)css/…
• React, redux, react-router,
and so much more
• React/other component libraries
• Development facilities hot reload
• Need for debugging…
• … and production build
Webpack proposes ways to manage all this
2017 cedric.hartland@gmail.com 41
Development – faster, better, stronger
• Webpack dev facilities
• Hot reload inject changes
in current app state
• Continuously build
• Bundling with debuging
• Proxy to back-end
• use 1 to many back-end
implementations
Reduce development downtimes
2017 cedric.hartland@gmail.com 42
React – redux dev tools
• Provide extra features to dev tools for debugging and scenario testing
2017 cedric.hartland@gmail.com 43
Going further…
From newbie to less newbie
2017 cedric.hartland@gmail.com 44
React
• We saw most of it already
• We could elaborate more on best practices…
2017 cedric.hartland@gmail.com 45
Redux
• Redux propose a framework for (web) application design
• By the way: redux is the concept, Redux an implementation of that concept
• Redux proposes data manipulation through reducer functions
• Combining reducers can help more elaborate data processing
• Normalizing data can help improving data manipulation and concistency
• Document based model
• Relational model mapping
• Using immutability libraries may help staying on the tracks of functional
programming and avoid pitfall bugs
2017 cedric.hartland@gmail.com 46
Redux – reducers and combinations
• One reducer a
• State will be state = { a: {…} }
• When reducer a activates, it’s input state is not state but state.a
• Combine 2 reducers (a, b)
• State will be state = { a: { … }, b: { … } }
• Reducer a consumes state.a and reducer b state.b
• Combine and sub-combine a, (b, c)
• State will be
• state = { a: { … }, bc: { b: { … }, c: { …} } }
• or state = { a: { … }, b: { … }, c: { …} }
• Reducer bc can exist as a sliced reducer that has access to state.b & state.c
2017 cedric.hartland@gmail.com 47
Redux – Data normalization
• Different reducers work on different state data
• Complex data structures may require elaborate operations
• Share actions across reducers
• Data duplication across reducers
• Those require extra synchronization effort when writing or updating code
• Accessing data may not be easy or consistent by default
• Normalizing data can help normalizr
• Relational mapping to structure data client side database !
• Get rid of data duplication
• Separate collections from elements
2017 cedric.hartland@gmail.com 48

More Related Content

What's hot

What's hot (20)

React и redux
React и reduxReact и redux
React и redux
 
React, Redux, ES2015 by Max Petruck
React, Redux, ES2015   by Max PetruckReact, Redux, ES2015   by Max Petruck
React, Redux, ES2015 by Max Petruck
 
Switch to React.js from AngularJS developer
Switch to React.js from AngularJS developerSwitch to React.js from AngularJS developer
Switch to React.js from AngularJS developer
 
Introduction to react and redux
Introduction to react and reduxIntroduction to react and redux
Introduction to react and redux
 
React for Dummies
React for DummiesReact for Dummies
React for Dummies
 
React & Redux
React & ReduxReact & Redux
React & Redux
 
Intro to ReactJS
Intro to ReactJSIntro to ReactJS
Intro to ReactJS
 
React & Redux
React & ReduxReact & Redux
React & Redux
 
Redux vs Alt
Redux vs AltRedux vs Alt
Redux vs Alt
 
React with Redux
React with ReduxReact with Redux
React with Redux
 
ReactJs presentation
ReactJs presentationReactJs presentation
ReactJs presentation
 
Getting started with Redux js
Getting started with Redux jsGetting started with Redux js
Getting started with Redux js
 
Better React state management with Redux
Better React state management with ReduxBetter React state management with Redux
Better React state management with Redux
 
An Introduction to ReactJS
An Introduction to ReactJSAn Introduction to ReactJS
An Introduction to ReactJS
 
React redux
React reduxReact redux
React redux
 
ProvJS: Six Months of ReactJS and Redux
ProvJS:  Six Months of ReactJS and ReduxProvJS:  Six Months of ReactJS and Redux
ProvJS: Six Months of ReactJS and Redux
 
Redux js
Redux jsRedux js
Redux js
 
Getting Started With ReactJS
Getting Started With ReactJSGetting Started With ReactJS
Getting Started With ReactJS
 
Designing applications with Redux
Designing applications with ReduxDesigning applications with Redux
Designing applications with Redux
 
ReactJS for Beginners
ReactJS for BeginnersReactJS for Beginners
ReactJS for Beginners
 

Similar to React & redux

Comparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAsComparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAsJennifer Estrada
 
Getting started with react &amp; redux
Getting started with react &amp; reduxGetting started with react &amp; redux
Getting started with react &amp; reduxGirish Talekar
 
2018 02-22 React, Redux & Building Applications that Scale | React
2018 02-22 React, Redux & Building Applications that Scale | React2018 02-22 React, Redux & Building Applications that Scale | React
2018 02-22 React, Redux & Building Applications that Scale | ReactCodifly
 
Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016Marco Breveglieri
 
Module Architecture of React-Redux Applications
Module Architecture of React-Redux ApplicationsModule Architecture of React-Redux Applications
Module Architecture of React-Redux ApplicationsAndrii Sliusar
 
Learning AngularJS - Complete coverage of AngularJS features and concepts
Learning AngularJS  - Complete coverage of AngularJS features and conceptsLearning AngularJS  - Complete coverage of AngularJS features and concepts
Learning AngularJS - Complete coverage of AngularJS features and conceptsSuresh Patidar
 
Action-Domain-Responder: A Web-Specific Refinement of Model-View-Controller
Action-Domain-Responder: A Web-Specific Refinement of Model-View-ControllerAction-Domain-Responder: A Web-Specific Refinement of Model-View-Controller
Action-Domain-Responder: A Web-Specific Refinement of Model-View-ControllerPaul Jones
 
An Introduction to Domain Driven Design in PHP
An Introduction to Domain Driven Design in PHPAn Introduction to Domain Driven Design in PHP
An Introduction to Domain Driven Design in PHPChris Renner
 
An Overview of the React Ecosystem
An Overview of the React EcosystemAn Overview of the React Ecosystem
An Overview of the React EcosystemFITC
 
Dependency injection Drupal Camp Wrocław 2014
Dependency injection Drupal Camp Wrocław 2014Dependency injection Drupal Camp Wrocław 2014
Dependency injection Drupal Camp Wrocław 2014Greg Szczotka
 
SQL in the Hybrid World
SQL in the Hybrid WorldSQL in the Hybrid World
SQL in the Hybrid WorldTanel Poder
 
Дмитрий Тежельников «Разработка вэб-решений с использованием Asp.NET.Core и ...
Дмитрий Тежельников  «Разработка вэб-решений с использованием Asp.NET.Core и ...Дмитрий Тежельников  «Разработка вэб-решений с использованием Asp.NET.Core и ...
Дмитрий Тежельников «Разработка вэб-решений с использованием Asp.NET.Core и ...MskDotNet Community
 
Planbox Backbone MVC
Planbox Backbone MVCPlanbox Backbone MVC
Planbox Backbone MVCAcquisio
 
Action-Domain-Responder: A Refinement of MVC
Action-Domain-Responder: A Refinement of MVCAction-Domain-Responder: A Refinement of MVC
Action-Domain-Responder: A Refinement of MVCPaul Jones
 
React Js Simplified
React Js SimplifiedReact Js Simplified
React Js SimplifiedSunil Yadav
 
Server rendering-talk
Server rendering-talkServer rendering-talk
Server rendering-talkDaiwei Lu
 

Similar to React & redux (20)

Comparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAsComparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAs
 
reactJS
reactJSreactJS
reactJS
 
Getting started with react &amp; redux
Getting started with react &amp; reduxGetting started with react &amp; redux
Getting started with react &amp; redux
 
Reactjs
Reactjs Reactjs
Reactjs
 
2018 02-22 React, Redux & Building Applications that Scale | React
2018 02-22 React, Redux & Building Applications that Scale | React2018 02-22 React, Redux & Building Applications that Scale | React
2018 02-22 React, Redux & Building Applications that Scale | React
 
Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016
 
React introduction
React introductionReact introduction
React introduction
 
Module Architecture of React-Redux Applications
Module Architecture of React-Redux ApplicationsModule Architecture of React-Redux Applications
Module Architecture of React-Redux Applications
 
React.js at Cortex
React.js at CortexReact.js at Cortex
React.js at Cortex
 
Learning AngularJS - Complete coverage of AngularJS features and concepts
Learning AngularJS  - Complete coverage of AngularJS features and conceptsLearning AngularJS  - Complete coverage of AngularJS features and concepts
Learning AngularJS - Complete coverage of AngularJS features and concepts
 
Action-Domain-Responder: A Web-Specific Refinement of Model-View-Controller
Action-Domain-Responder: A Web-Specific Refinement of Model-View-ControllerAction-Domain-Responder: A Web-Specific Refinement of Model-View-Controller
Action-Domain-Responder: A Web-Specific Refinement of Model-View-Controller
 
An Introduction to Domain Driven Design in PHP
An Introduction to Domain Driven Design in PHPAn Introduction to Domain Driven Design in PHP
An Introduction to Domain Driven Design in PHP
 
An Overview of the React Ecosystem
An Overview of the React EcosystemAn Overview of the React Ecosystem
An Overview of the React Ecosystem
 
Dependency injection Drupal Camp Wrocław 2014
Dependency injection Drupal Camp Wrocław 2014Dependency injection Drupal Camp Wrocław 2014
Dependency injection Drupal Camp Wrocław 2014
 
SQL in the Hybrid World
SQL in the Hybrid WorldSQL in the Hybrid World
SQL in the Hybrid World
 
Дмитрий Тежельников «Разработка вэб-решений с использованием Asp.NET.Core и ...
Дмитрий Тежельников  «Разработка вэб-решений с использованием Asp.NET.Core и ...Дмитрий Тежельников  «Разработка вэб-решений с использованием Asp.NET.Core и ...
Дмитрий Тежельников «Разработка вэб-решений с использованием Asp.NET.Core и ...
 
Planbox Backbone MVC
Planbox Backbone MVCPlanbox Backbone MVC
Planbox Backbone MVC
 
Action-Domain-Responder: A Refinement of MVC
Action-Domain-Responder: A Refinement of MVCAction-Domain-Responder: A Refinement of MVC
Action-Domain-Responder: A Refinement of MVC
 
React Js Simplified
React Js SimplifiedReact Js Simplified
React Js Simplified
 
Server rendering-talk
Server rendering-talkServer rendering-talk
Server rendering-talk
 

Recently uploaded

CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
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.docxComplianceQuest1
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
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.pdfkalichargn70th171
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
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 CCTVshikhaohhpro
 
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 Modelsaagamshah0812
 
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.pdfkalichargn70th171
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
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.comFatema Valibhai
 
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...ICS
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
+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
 

Recently uploaded (20)

CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
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
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
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
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
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
 
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
 
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
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
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
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
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
 
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...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
+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...
 

React & redux

  • 1. React & Redux Keep your head cool and focused, there’s a tons of stuff to see today Cedric Hartland
  • 2. A project we’re targeting 2017 cedric.hartland@gmail.com 2
  • 3. React – a gentle introduction Javascript library for building user interfaces 2017 cedric.hartland@gmail.com 3
  • 4. React – a library that defines views through components • In a declarative way • Components means reusability close to object oriented paradigm • Given an application state, renders some shadow DOM application state are inputs named properties • Business logic, state flow and DOM rendering are independent • Optimized rendering engine actually inspired from game engines • Little assumption on application structure can “easily” integrate with other technologies • Can render on server side SEO please What else ? Not so much more 2017 cedric.hartland@gmail.com 4
  • 5. React – what’s actually good in it ? • Components • Enhanced reusability well, keep it generic if you plan on reusing… it’s all about OOP • Rendering lifecycle with optimizations • Basic type checking not so basic with propTypes • Becomes powerful with ES6 and more it’s not react, it’s ES6 • Dependency management • Uptaded syntax and language features • Css inclusions • Arguably JSX • As opposed to string based templates • Don’t blame too quick, tsx exists too 2017 cedric.hartland@gmail.com 5
  • 6. React – first thing first: JSX • Update to JS – ease the code readability for React • Elements, expressions, functions, etc. • CSS horror !! Js based CSS injection, good alternative with CSS imports/modular CSS 2017 cedric.hartland@gmail.com 6 React.createElement( "div", { "class": "app-head" }, React.createElement("h1", null, "Portfolio Quality" ), React.createElement( Tiles, { color: "blue" }, React.createElement(Tile, { value: 2.8294564, title: "Total quality" }), React.createElement(Tile, { value: 2.75189, title: "Security" }), React.createElement(Tile, { value: 2.82154, title: "Robustness" }), React.createElement(Tile, { value: 2.98678, title: "Efficiency" }), React.createElement(Tile, { value: 2.74234, title: "Changeability" }), React.createElement(Tile, { value: 2.76354, title: "Transferability" }) ) ); <div class="app-head" > <h1>Portfolio Quality</h1> <Tiles color="blue" > <Tile value={2.8294564} title="Total quality" /> <Tile value={2.75189} title="Security" /> <Tile value={2.82154} title="Robustness" /> <Tile value={2.98678} title="Efficiency" /> <Tile value={2.74234} title="Changeability" /> <Tile value={2.76354} title="Transferability" /> </Tiles> </div> ES5 JSX
  • 7. A (not so) simple component 2017 cedric.hartland@gmail.com 7 class Tile extends React.Component { static propTypes = { value: React.PropTypes.number, title: React.PropTypes.string }; render() { return ( <div className="tile"> <div className="tile-header">{this.props.title}</div> <div className="tile-value">{numeral(this.props.value).format('0.00')}</div> </div> ); } } Properties types JSX declarations Reusable class or function Optional parenthesis wrapping Js Expressions in brackets
  • 8. Using this component 2017 cedric.hartland@gmail.com 8 <div className="tiles"> <Tile value={2.8294564} title="Total quality" /> <Tile value={2.75189} title="Security" /> … </div> <div className="tiles"> {data.map((sample, index) => { return <Tile key={index} {...sample} />; })} </div> Reuse component as an html element From collection of data to collection of components Properties passed explicitely to the component Properties are submitted implicitely from object Key is required for collections So React can omptimize re- rendering
  • 9. Adding user interactions 2017 cedric.hartland@gmail.com 9 class Filter extends React.Component { … render() { return ( <div className="filter-input"> <input type="text" value={this.props.filterText} placeholder={this.props.placeholder} onChange={this.props.handleFilter} /> </div>); } } Beware, binding to this use ES6 ! Bind functions to events
  • 11. A few words on performance • Mounting (first render) is not cheap estimated x5 times slower than jquery • Creation of shadow DOM • Rendering of shadow DOM elements to actual DOM • Updating state 1. Component properties (inputs) changes trigger re-rendering comparing properties has negative impact on performance 2. Rendering creates a shadow DOM little impact on performance 3. Compare new shadow DOM to previous one negative impact on performance 4. Rendering of only differences to actual DOM strong positive impact on performance • Optimize via shouldComponentUpdate • Bring business logic and guess whether the component should call render at all not rendering when data are not changing has positive impact on performance 2017 cedric.hartland@gmail.com 11
  • 12. React • A few words before moving to next topic… • …just in case it was not that clear • React is designed in a declarative way • It can define it’s own internal state, but… • ...most components should always return same content for given input and not have internal state dumb components, pure components • State only comes from data properties, state • No more jquery, backbone or whatever rendering tweaks on user interactions or from other sources • A single DOM source of truth is the output of render function • Application state only belong in data properties, state, dom reflects this 2017 cedric.hartland@gmail.com 12
  • 13. React – dumb & smart components • Application state is not held in component • Many components are said to be dumb • only display data • Dispatch events from user actions • Some smarter components • Operate other components and user actions functions • Some bind to data-source to manage application state updates 2017 cedric.hartland@gmail.com 13
  • 14. Few words on i18n • Available with key/value extractions package react-intl • Turn • Into 2017 cedric.hartland@gmail.com 14 <Filter filterText={this.props.applications.filter} handleFilter={this.handleFilter} placeholder='Search...' /> <Filter filterText={this.props.applications.filter} handleFilter={this.handleFilter} placeholder={<FormattedMessage id="applications.filterMesssage" defaultMessage="Search…" /> } /> Propose ID and default message Work with plurality and variables
  • 15. React & Redux Rock & Roll 2017 cedric.hartland@gmail.com 15
  • 16. Redux – what the flux ? • Many frameworks and approaches follows MVC like patterns • Model manages behavior and data • View represent the display of the model in UI • Controller takes user input, manipulates model and cause views to update • MVC existed before I was born and still exist so it is kind of a norm • Bidirectional communications → causes cycles and create high complexity as met in AAD, AED, Highlight, etc. where 1 data change causes given views to render several times or indefinitely due to side effects 2017 cedric.hartland@gmail.com 16
  • 17. Redux – what the flux ? • React consumes data and produce DOM React updates DOM when data changes • Need for a data-source management workflow • Single source of truth • Whole application state in the centralized data store not hidden in DOM or other weird places • Flux, the original worflow : 2017 cedric.hartland@gmail.com 17 Dispatcher View Store Action
  • 18. Redux - workflow close to that of flux • Motivation • MVC makes it hard to understand & debug application model update another model, then update a view that update a model, then… • SPAs high complexity data, interactions, asynchronicity, routing, etc. data mutation and asynchronicity makes it hard to reason about the application • Core principles • Single source of truth • The state of application stored in single object tree in single data store • State is read-only • Changing state requires an action that describes operation • Changes are made with pure functions • New state is new object no mutations 2017 cedric.hartland@gmail.com 19
  • 19. Redux – flux • Store is defined through • State • Reducers state mutator functions • Consumes current state • Consumes actions operations that could update state • Produces new state …or return the previous state if not changed (state, action) → state’ • Reducers can be combined • Divide & conquer • Reducers have to be pure functions • If states are different, their reference pointer are different • Benefit from predictability and testability • No need for deep object comparison through components lifecycle save on most expensive operation 2017 cedric.hartland@gmail.com 20
  • 20. Actions • Action basic structure • Type e.g. APPLICATION_FETCH • Payload e.g. { id: appId } • Action creators • Centralize business logic processing avoid diverging duplicates from discording places in code • Delegate type ↔ payload construction from dedicated functions • Actions payload processing is business logic related independent from data stores and views • Dispatching actions • Enforce loose coupling of code parts • Event based actions dispatching • Enable middleware based payload consumption and/or transformation 2017 cedric.hartland@gmail.com 21
  • 21. Redux – workflow 2017 cedric.hartland@gmail.com 22 Dispatcher View Store Action
  • 22. Redux – workflow 2017 cedric.hartland@gmail.com 23 Dispatcher View Store Action Reducers R R R State
  • 23. Redux – workflow 2017 cedric.hartland@gmail.com 24 Dispatcher View Store Action Reducers R R R State middlewares API Logs Delay actions Loop actions Crash report …
  • 24. Redux – workflow 2017 cedric.hartland@gmail.com 25 Dispatcher View Store Action Reducers R R R State middlewares API Logs Delay actions Loop actions Crash report … event
  • 25. Redux – workflow 2017 cedric.hartland@gmail.com 26 Dispatcher View Store Action Reducers R R R State middlewares API Logs Delay actions Loop actions Crash report … action
  • 26. Redux – workflow 2017 cedric.hartland@gmail.com 27 Dispatcher View Store Action Reducers R R R State middlewares API Logs Delay actions Loop actions Crash report … action
  • 27. Redux – workflow 2017 cedric.hartland@gmail.com 28 Dispatcher View Store Action Reducers R R R State middlewares API Logs Delay actions Loop actions Crash report … state action
  • 28. Redux – workflow 2017 cedric.hartland@gmail.com 29 Dispatcher View Store Action Reducers R R R State middlewares API Logs Delay actions Loop actions Crash report … new state
  • 29. Redux – workflow 2017 cedric.hartland@gmail.com 30 Dispatcher View Store Action Reducers R R R State middlewares API Logs Delay actions Loop actions Crash report … action
  • 30. Redux – workflow 2017 cedric.hartland@gmail.com 31 Dispatcher View Store Action Reducers R R R State middlewares API Logs Delay actions Loop actions Crash report … action
  • 31. Redux – workflow 2017 cedric.hartland@gmail.com 32 Dispatcher View Store Action Reducers R R R State middlewares API Logs Delay actions Loop actions Crash report … state action
  • 32. Redux – workflow 2017 cedric.hartland@gmail.com 33 Dispatcher View Store Action Reducers R R R State middlewares API Logs Delay actions Loop actions Crash report … new state
  • 33. Rock & Roll • React • Render components • Optimized rendering workflow • Redux • Optimize weak parts of react rendering • Together • Makes model – view transformations unidirectional • Optimize on view rendering and data processing “easier” to debug and understand + efficient rendering 2017 cedric.hartland@gmail.com 34
  • 34. Application structure • sources ⁄ api/ // contains url information (builders) to (RESTful) API resources ⁄ business/ // contains data description and manipulations (redux workflow) ⁄ components/ // contains React dumb components ⁄ containers/ // contains React smart components ⁄ core/ // general application configuration skeleton ⁄ index.html // SPA entry point ⁄ main.jsx // SPA code entry point ⁄ store.js // redux data store setup 2017 cedric.hartland@gmail.com 35
  • 35. Business logic • sources ⁄ … ⁄ business/ ⁄ any-concept/ ⁄ specs/ // tests for business files, may be flat to folder or in such subfolder ⁄ actions.js // action creators (business logic operations there) ⁄ constants.js* // reusable constants (e.g. action variables) ⁄ reducers.js // reducer functions ⁄ sagas.js* // sagas middleware operations ⁄ ..middleware.js // other possible middleware linked to business logic concept ⁄ … Components with * are optional depending on context 2017 cedric.hartland@gmail.com 36
  • 36. API ? • Api lists / links API urls and querying of those it’s all about getting data • Use of ES6 fetch • Or use of frameworks or libraries such as axios… 2017 cedric.hartland@gmail.com 37 axios('REST/applications') .then((response) => { return response.data.applications; }).catch((error) => { throw error; });
  • 37. Sagas ? • Operate side-effect operations • asynchronous operations e.g. manage data fetch from server • Cache accesses • Rely on generator pattern from ES6 2017 cedric.hartland@gmail.com 38 function* sagas() { yield put({type: 'APPLICATIONS_FETCH_PENDING'}); try { yield fork (takeLatest, 'APPLICATIONS_FETCH', fetchApplications, ApiApplications); } catch (error) { yield put({type: 'APPLICATIONS_FETCH_ERROR', payload: error}); } } Generator function Dispatch actions Back to reducer Wait for command to be done before moving to next one Define network reuse policy
  • 38. Almost done… Build, enhanced development process and how to test 2017 cedric.hartland@gmail.com 39
  • 39. Testing • As usual, • Need for unit tests mocha, jasmine, jed, enzyme, etc. • Need for integration tests • Selenium, Casperjs, Nightwatch, etc. • Consider mock servers option • Need for manual testing • Again, consider mock server option • Need to run tests on real browsers Nothing really new out there 2017 cedric.hartland@gmail.com 40
  • 40. Packaging • Not so little development stack • jsx/es6/es2016/… • sass/less/modular (s)css/… • React, redux, react-router, and so much more • React/other component libraries • Development facilities hot reload • Need for debugging… • … and production build Webpack proposes ways to manage all this 2017 cedric.hartland@gmail.com 41
  • 41. Development – faster, better, stronger • Webpack dev facilities • Hot reload inject changes in current app state • Continuously build • Bundling with debuging • Proxy to back-end • use 1 to many back-end implementations Reduce development downtimes 2017 cedric.hartland@gmail.com 42
  • 42. React – redux dev tools • Provide extra features to dev tools for debugging and scenario testing 2017 cedric.hartland@gmail.com 43
  • 43. Going further… From newbie to less newbie 2017 cedric.hartland@gmail.com 44
  • 44. React • We saw most of it already • We could elaborate more on best practices… 2017 cedric.hartland@gmail.com 45
  • 45. Redux • Redux propose a framework for (web) application design • By the way: redux is the concept, Redux an implementation of that concept • Redux proposes data manipulation through reducer functions • Combining reducers can help more elaborate data processing • Normalizing data can help improving data manipulation and concistency • Document based model • Relational model mapping • Using immutability libraries may help staying on the tracks of functional programming and avoid pitfall bugs 2017 cedric.hartland@gmail.com 46
  • 46. Redux – reducers and combinations • One reducer a • State will be state = { a: {…} } • When reducer a activates, it’s input state is not state but state.a • Combine 2 reducers (a, b) • State will be state = { a: { … }, b: { … } } • Reducer a consumes state.a and reducer b state.b • Combine and sub-combine a, (b, c) • State will be • state = { a: { … }, bc: { b: { … }, c: { …} } } • or state = { a: { … }, b: { … }, c: { …} } • Reducer bc can exist as a sliced reducer that has access to state.b & state.c 2017 cedric.hartland@gmail.com 47
  • 47. Redux – Data normalization • Different reducers work on different state data • Complex data structures may require elaborate operations • Share actions across reducers • Data duplication across reducers • Those require extra synchronization effort when writing or updating code • Accessing data may not be easy or consistent by default • Normalizing data can help normalizr • Relational mapping to structure data client side database ! • Get rid of data duplication • Separate collections from elements 2017 cedric.hartland@gmail.com 48

Editor's Notes

  1. SOLID Single responsibility Open (for extensions) closed (for modifications) Liskove substitutions – objects replacables with instances of subtypes Interface segregation Dependency investion – rely on abstractions
  2. MVC – around 1976