SlideShare a Scribd company logo
Redux data flow with angular
REDUX DATA FLOW WITH
ANGULAR
SPAs Are Complex
Service
Component
Service
ComponentComponent
Service
Component
Service
ComponentComponent
Component
Component
Service
Service Component
Service
Service
Component
Service
ComponentComponent
Component
Component
Service
Service Component
Service
Service
Component
Service
ComponentComponent
Component
Component
Service
Service Component
Service
Service
Component
Service
ComponentComponent
Component
Component
Service
Service Component
Service
Then you make a small change…
Redux data flow with angular
About Me
• sparXys CEO and senior consultant
• Microsoft MVP in the last 8 years
• Pro Single Page Application Development (Apress) co-author
• 4 Microsoft Official Courses (MOCs) co-author
• GDG Rishon and AngularUP co-organizer
Agenda
• The Redux pattern
• Combining Redux and Angular
• ng2-redux library in a nutshell
Known SPA Complexity Solutions
• Command Query Responsibility Segregation (CQRS)
• Event Sourcing
• Flux
• And more
Redux
• Design pattern based on Flux
• But it’s not Flux!
• Predictable state container for JavaScript apps
Redux Principles
1. Single source of truth
Single Source of Truth
• The application state is stored in an object tree within a single store
let state = store.getState();
Redux Principles
1. Single source of truth
2. State is read-only
State is Read-Only
• The only way to mutate the state is to emit an action describing what
happened
store.dispatch({
type: 'ADD_GROCERY_ITEM',
item: { productToBuy: 'Milk' }
});
store.dispatch({
type: 'REMOVE_GROCERY_ITEM',
index: 3
});
Redux Principles
1. Single source of truth
2. State is read-only
3. Changes are made with pure functions
Changes Are Made with Pure Functions
• To specify how the state is transformed by actions, you write a pure
function
function groceryItemReducer(state, action) {
switch (action.type) {
case 'ADD_GROCERY_ITEM':
return object.assign({}, state, {
groceryItems: [
action.item,
…state.groceryItems
]
};
default:
return state;
}
}
Let’s drill down
Redux Actors
Action
Creators
View
ReducersStore
Actions
• Plain JavaScript objects
• Include
• Type – action type
• Payload – the change that should occur
let action = {
type: 'ADD_GROCERY_ITEM',
item: { productToBuy: 'Milk' }
};
Action
Creators
Action Creators
• Functions that return actions
const ADD_GROCERY_ITEM = 'ADD_GROCERY_ITEM';
function addGroceryItem(item) {
return {
type: ADD_GROCERY_ITEM,
item: item
};
}
Action
Creators
Reducers
• Change the state in response to things that happened in the
application
• Pure functions
function groceryItemReducer(state, action) {
switch (action.type) {
case ADD_GROCERY_ITEM:
return object.assign({}, state, {
groceryItems: [
action.item,
…state.groceryItems
]
};
default:
return state;
}
}
Reducers
Store
• Only one store object
• Store data accessed through getState function
• Updates only in response to dispatching an action
import {createStore} from ‘redux’;
import {groceryItemReducer} from ‘./reducers/groceryItemReducer’;
const store = createStore(groceryItemReducer);
Store
Redux Data Flow
Action
Creators
View
ReducersStore
interaction (click, mouse etc.)
dispatch(action) (previous state, action)
(new state)
(current state)
Redux Data Flow – Cont.
Action
Creators
View
ReducersStore
interaction (click, mouse etc.)
dispatch(action) (previous state, action)
(new state)
(current state)
Outside Action
(push, Ajax callback
and etc.)
Redux Library API
• Redux is a small and compact library:
• createStore(reducer)
• combineReducers(reducers)
• applyMiddleware(middlewares)
• compose(functions)
• bindActionCreators(creators, dispatch)
• Store API:
• store.dispatch(action)
• store.getState()
• store.subscribe(listener)
DEMO: REDUX IN ACTION
Redux Middleware
• Extension point between dispatching an action and the reducer
• Middleware examples:
• Logging
• Async operations
• Routing
const middleware = store => next => action => {
// do something before dispatcher
let result = next(action);
// do something after dispatcher
return result;
}
const store = createStore(reducer, applyMiddleware(middleware));
DEMO: REDUX MIDDLEWARE
WHAT ABOUT ANGULAR?
Angular and Redux
• Redux can be applied in Angular oriented applications
• It’s a data flow pattern
• Popular Angular & Redux libraries:
• ng2-redux
• ngrx/store
NG2-REDUX
https://github.com/angular-redux/ng2-redux
npm install --save ng2-redux
ng2-redux - Setup
• Add the module
• Create the store and provide it in the main module
import { NgReduxModule, NgRedux } from 'ng2-redux';
@NgModule({
imports: [ /* ... */, NgReduxModule ]
})
class AppModule {
constructor(ngRedux: NgRedux<IAppState>) {
ngRedux.provideStore(store);
}
}
ng2-redux - Usage
• Use the @select decorator and dispatch function:
class App {
@select() counter: Observable<number>;
constructor(private ngRedux: NgRedux<IAppState>) {}
increment() {
this.ngRedux.dispatch({ type: INCREMENT});
}
}
DEMO: REDUX + ANGULAR
Summary
• Redux
• Is a data flow design pattern
• Reduces complexity when building big SPAs
• Can be applied in Angular apps
Resources
• Redux:
https://github.com/reactjs/redux
• ng2-redux:
https://github.com/angular-redux/ng2-redux
• ngrx/store:
https://github.com/ngrx/store
• My Blog – http://www.gilfink.net
• Follow me on Twitter – @gilfink
Thank You!

More Related Content

PDF
Redux data flow with angular
PDF
Who's afraid of front end databases
PDF
Intershop Commerce Management with Microsoft SQL Server
PPTX
TechDays NL 2016 - Building your scalable secure IoT Solution on Azure
PPTX
What's new in the July 2017 Update for Dynamics 365 - Developer features
PDF
Android architecture components with cloud firestore
PDF
Whos afraid of front end databases?
PDF
How to write your database: the story about Event Store
Redux data flow with angular
Who's afraid of front end databases
Intershop Commerce Management with Microsoft SQL Server
TechDays NL 2016 - Building your scalable secure IoT Solution on Azure
What's new in the July 2017 Update for Dynamics 365 - Developer features
Android architecture components with cloud firestore
Whos afraid of front end databases?
How to write your database: the story about Event Store

What's hot (20)

PDF
Azure Data Factory v2
PPTX
Analyzing StackExchange Data with Azure Data Lake (Tom Kerkhove @ Integration...
PPTX
Introduction to Event Sourcing
PPTX
Elastic stack Presentation
PPTX
DocumentDB - NoSQL on Cloud at Reboot2015
PDF
Feature store Overview St. Louis Big Data IDEA Meetup aug 2020
PDF
Accelerating query processing with materialized views in Apache Hive
PPTX
Intro to Azure Data Factory v1
PPTX
Modern ETL: Azure Data Factory, Data Lake, and SQL Database
PPTX
Azure Data Factory for Azure Data Week
ODP
BigQuery at AppsFlyer - past, present and future
PPTX
Azure Data Factory for Redmond SQL PASS UG Sept 2018
PPTX
ASP.NET Lecture 4
PDF
Making App Developers More Productive
PDF
Introduction to Azure Data Factory
PDF
Journey to containers by Chet Lintz - AWS Chicago Jan 17,2018 user group on C...
PDF
An overview of BigQuery
PPTX
Azure data factory
PDF
Pathway to Cloud-Native .NET
PPTX
Microsoft Azure Data Factory Hands-On Lab Overview Slides
Azure Data Factory v2
Analyzing StackExchange Data with Azure Data Lake (Tom Kerkhove @ Integration...
Introduction to Event Sourcing
Elastic stack Presentation
DocumentDB - NoSQL on Cloud at Reboot2015
Feature store Overview St. Louis Big Data IDEA Meetup aug 2020
Accelerating query processing with materialized views in Apache Hive
Intro to Azure Data Factory v1
Modern ETL: Azure Data Factory, Data Lake, and SQL Database
Azure Data Factory for Azure Data Week
BigQuery at AppsFlyer - past, present and future
Azure Data Factory for Redmond SQL PASS UG Sept 2018
ASP.NET Lecture 4
Making App Developers More Productive
Introduction to Azure Data Factory
Journey to containers by Chet Lintz - AWS Chicago Jan 17,2018 user group on C...
An overview of BigQuery
Azure data factory
Pathway to Cloud-Native .NET
Microsoft Azure Data Factory Hands-On Lab Overview Slides
Ad

Similar to Redux data flow with angular (20)

PDF
Redux data flow with angular 2
PPTX
Spfx with react redux
PDF
Redux js
PDF
An Overview of the React Ecosystem
PPTX
Redux Like Us
PPTX
Damian Kmiecik - Road trip with Redux
PPTX
downloads_introduction to redux.pptx
PPTX
Getting started with Redux js
PPTX
Introduction to react and redux
PPTX
Redux workshop
PDF
React state management with Redux and MobX
PPTX
React & redux
PDF
Making react part of something greater
PPSX
React introduction
PDF
React.js+Redux Workshops
PDF
Building React Applications with Redux
PPTX
Academy PRO: React JS. Redux & Tooling
PDF
Reactивная тяга
PDF
Introduction to React, Flux, and Isomorphic Apps
PDF
Gabor Varadi - Reactive State Management with Jetpack Components
Redux data flow with angular 2
Spfx with react redux
Redux js
An Overview of the React Ecosystem
Redux Like Us
Damian Kmiecik - Road trip with Redux
downloads_introduction to redux.pptx
Getting started with Redux js
Introduction to react and redux
Redux workshop
React state management with Redux and MobX
React & redux
Making react part of something greater
React introduction
React.js+Redux Workshops
Building React Applications with Redux
Academy PRO: React JS. Redux & Tooling
Reactивная тяга
Introduction to React, Flux, and Isomorphic Apps
Gabor Varadi - Reactive State Management with Jetpack Components
Ad

More from Gil Fink (20)

PDF
Becoming a Tech Speaker
PPTX
Web animation on steroids web animation api
PDF
The Time for Vanilla Web Components has Arrived
PDF
Stencil the time for vanilla web components has arrived
PDF
Stencil the time for vanilla web components has arrived
PDF
Stencil: The Time for Vanilla Web Components has Arrived
PDF
Stencil the time for vanilla web components has arrived
PDF
Being a tech speaker
PDF
Working with Data in Service Workers
PDF
Demystifying Angular Animations
PDF
Who's afraid of front end databases?
PDF
One language to rule them all type script
PDF
End to-end apps with type script
PDF
Web component driven development
PDF
Web components
PDF
Biological Modeling, Powered by AngularJS
PDF
Biological modeling, powered by angular js
PDF
Web components the future is here
PDF
One language to rule them all type script
PDF
Web Components - The Future is Here
Becoming a Tech Speaker
Web animation on steroids web animation api
The Time for Vanilla Web Components has Arrived
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrived
Stencil: The Time for Vanilla Web Components has Arrived
Stencil the time for vanilla web components has arrived
Being a tech speaker
Working with Data in Service Workers
Demystifying Angular Animations
Who's afraid of front end databases?
One language to rule them all type script
End to-end apps with type script
Web component driven development
Web components
Biological Modeling, Powered by AngularJS
Biological modeling, powered by angular js
Web components the future is here
One language to rule them all type script
Web Components - The Future is Here

Recently uploaded (20)

PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Electronic commerce courselecture one. Pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Cloud computing and distributed systems.
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPT
Teaching material agriculture food technology
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Sensors and Actuators in IoT Systems using pdf
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PDF
Advanced Soft Computing BINUS July 2025.pdf
PDF
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
PDF
Chapter 2 Digital Image Fundamentals.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
PDF
KodekX | Application Modernization Development
Spectral efficient network and resource selection model in 5G networks
Electronic commerce courselecture one. Pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Cloud computing and distributed systems.
Dropbox Q2 2025 Financial Results & Investor Presentation
Diabetes mellitus diagnosis method based random forest with bat algorithm
Teaching material agriculture food technology
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
NewMind AI Monthly Chronicles - July 2025
Sensors and Actuators in IoT Systems using pdf
madgavkar20181017ppt McKinsey Presentation.pdf
Advanced Soft Computing BINUS July 2025.pdf
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
Chapter 2 Digital Image Fundamentals.pdf
Chapter 3 Spatial Domain Image Processing.pdf
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
KodekX | Application Modernization Development

Redux data flow with angular