SlideShare a Scribd company logo
REDUX & ANGULAR
UP & RUNNING
NIR KAUFMAN
AGENDA
what is redux?
how to use redux?
where Angular fits in?
where to go from here?
WHAT IS REDUX
REDUX IS A
DESIGN PATTERN
for managing a complex, ever changing state
in a challenging modern single page applications
SINGLE SOURCE
OF TRUTH
the state of your whole application is
stored within a single store
THE STATE IS
READ ONLY
the only way to mutate the state is to emit
an action describing what happened
PURE FUNCTIONS
to specify how the state is transformed
by actions, you write a pure function.
PURE*
FUNCTION
ACTION NEXT STATE
* No side-effects
reducer
const currentState = 0;

const action = {type: 'INCREASE'};



function reducer(action, currentState){



if(action.type === 'INCREASE') {

return currentState + 1;

}



return currentState;

}
const currentState = 0;

const action = {type: 'INCREASE'};



function reducer(action, currentState){



if(action.type === 'INCREASE') {

return currentState + 1;

}



return currentState;

}
const currentState = 0;

const action = {type: 'INCREASE'};



function reducer(action, currentState){



if(action.type === 'INCREASE') {

return currentState + 1;

}



return currentState;

}
const currentState = 0;

const action = {type: 'INCREASE'};



function reducer(action, currentState){



if(action.type === 'INCREASE') {

return currentState + 1;

}



return currentState;

}
const currentState = 0;

const action = {type: 'INCREASE'};



function reducer(action, currentState){



if(action.type === 'INCREASE') {

return currentState + 1;

}



return currentState;

}
HOW TO USE REDUX
REDUX IS A
TINY LIBRARY
which contains a function for creating a store,
and 4 other helpers functions that we can use.
import { createStore } from 'redux';



const store = createStore(reducer);
import { createStore } from 'redux';



const store = createStore(reducer);
STORE API
getState()
dispatch(action)
subscribe(listener)
replaceReducer(reducer)
THE STORE IS SIMPLE
TO UNDERSTAND
we can implement a working store
in less then 30 lines of code.
function createStore(reducer) {

let state = null;

const listeners = [];



function getState() {

return state;

}



function dispatch(action) {

state = reducer(state, action);

listeners.forEach(listener => listener())

}



function subscribe(listener) {

listeners.push(listener);

return function () {

let index = listeners.indexOf(listener);

listeners.splice(index, 1)

}

}



dispatch({ type:’@@INIT' });

return { getState, dispatch, subscribe }

}
CONNECTING THE
DOTS
now we can dispatch actions and be notified
when the state has changed.
dispatch
getState
STATE
ACTION
STOREUI
UI IS RENDERED
SOMETHING HAPPENED
ACTION DISPATCHED
STATE CHANGED
UI IS RENDERED
SOMETHING HAPPENED
ACTION DISPATCHED
STATE CHANGED
SOMETHING HAPPENED
UNI-DIRECTIONAL
DATA FLOW
sync flow
{ LIVE CODING }
let’s build a traffic light and see
redux in action!
INTERCEPTING THE
ACTION FLOW
this is done using middleware which can catch
the action before they hit the store.
async flow
STATE
ACTION
STOREUI
Middlewae
{ LIVE CODING }
implementing a simple logger
as a middleware.
ANGULAR & REDUX
JUST THE VIEW
api as actions
logic in middlewares & reducers
state inside a store
ANGULAR APP IS A
TREE OF COMPONENTS
each component is responsible for rendering a
a pert of the state, or dispatching actions.
CONTAINER
COMPONENT COMPONENT
STORE
[properties] (events)
actions
state
BINDING COMPONENTS
TO THE STORE
it’s straightforward but requires a lot of
boilerplate inside the component class.
NPM TO THE RESCUE!
FIND AN ADAPTOR
I will use the ‘angular2-redux-bindings’
for this example
class TodoListComponent {


constructor(){

this.unsubscribe = store.subscribe( () => this.renderList )

}

ngOnInit(){

this.renderList()

}



ngOnDestroy(){

this.unsubscribe()

}



addItem(item){

store.dispatch({

type: 'ADD_ITEM',

payload: item

})

}



renderList(){

this.list = store.getState().list;

}

}
class TodoListComponent {



@MapState('list')

private list;



@BindActions(addItem)

private addItem;



}
{ LIVE CODING }
let’s build the view layer using
Angular2 components
NEXT STEPS
PLAY WITH THE DEMO
https://github.com/nirkaufman/angular-redux-demo
Angular & Redux Workshop
https://leanpub.com/redux-book
REDUX BOOK
Angular & Redux Workshop
FURTHER READING
REDUX
http://redux.js.org/
https://egghead.io/series/getting-started-with-redux
CQRS & EVENT SOURCING
https://msdn.microsoft.com/en-us/library/dn568103.aspx
https://msdn.microsoft.com/en-us/library/dn589792.aspx
ANGULAR 2
angular-2-change-detection-explained.html
THANK YOU!
Read our blog:
http://blog.500tech.com
NIR KAUFMAN
nir@500tech.com
Head of Angular Development @ 500Tech

More Related Content

What's hot (20)

PPTX
React + Redux + TypeScript === ♥
Remo Jansen
 
PDF
Introduction to Redux (for Angular and React devs)
Fabio Biondi
 
PDF
Designing applications with Redux
Fernando Daciuk
 
PDF
Extending Kubernetes with Operators
peychevi
 
PDF
Manage the Flux of your Web Application: Let's Redux
Commit University
 
PDF
Data architectures in Angular & NGRX Introduction
Fabio Biondi
 
PDF
React js use contexts and useContext hook
Piyush Jamwal
 
PDF
Using redux
Jonas Ohlsson Aden
 
PDF
React state management with Redux and MobX
Darko Kukovec
 
PDF
The Road To Redux
Jeffrey Sanchez
 
PDF
From Big to Massive – Scalability in AngularJS Applications
Sebastian Fröstl
 
PDF
Unidirectional Data Flow with Reactor
Jason Larsen
 
PPTX
Reducers+flux=redux
Shmulik Chicvashvili
 
PDF
Cycle.js - Functional reactive UI framework (Nikos Kalogridis)
GreeceJS
 
PDF
Cycle.js - A functional reactive UI framework
Nikos Kalogridis
 
PDF
Introduction to ReactJS and Redux
Boris Dinkevich
 
PDF
Introduction to React Hooks
Felicia O'Garro
 
PPTX
React-JS Component Life-cycle Methods
ANKUSH CHAVAN
 
PDF
Making react part of something greater
Darko Kukovec
 
PDF
Unidirectional Data Flow in Swift
Jason Larsen
 
React + Redux + TypeScript === ♥
Remo Jansen
 
Introduction to Redux (for Angular and React devs)
Fabio Biondi
 
Designing applications with Redux
Fernando Daciuk
 
Extending Kubernetes with Operators
peychevi
 
Manage the Flux of your Web Application: Let's Redux
Commit University
 
Data architectures in Angular & NGRX Introduction
Fabio Biondi
 
React js use contexts and useContext hook
Piyush Jamwal
 
Using redux
Jonas Ohlsson Aden
 
React state management with Redux and MobX
Darko Kukovec
 
The Road To Redux
Jeffrey Sanchez
 
From Big to Massive – Scalability in AngularJS Applications
Sebastian Fröstl
 
Unidirectional Data Flow with Reactor
Jason Larsen
 
Reducers+flux=redux
Shmulik Chicvashvili
 
Cycle.js - Functional reactive UI framework (Nikos Kalogridis)
GreeceJS
 
Cycle.js - A functional reactive UI framework
Nikos Kalogridis
 
Introduction to ReactJS and Redux
Boris Dinkevich
 
Introduction to React Hooks
Felicia O'Garro
 
React-JS Component Life-cycle Methods
ANKUSH CHAVAN
 
Making react part of something greater
Darko Kukovec
 
Unidirectional Data Flow in Swift
Jason Larsen
 

Viewers also liked (20)

PDF
Redux with angular 2 - workshop 2016
Nir Kaufman
 
PDF
Managing state in Angular 1.x with Redux
500Tech
 
PDF
Angular2 & ngrx/store: Game of States
Oren Farhi
 
PDF
Data Structures in javaScript 2015
Nir Kaufman
 
PDF
Up & running with ECMAScript6
Nir Kaufman
 
PDF
Solid angular
Nir Kaufman
 
PDF
Angular Pipes Workshop
Nir Kaufman
 
PDF
How Angular2 Can Improve Your AngularJS Apps Today!
Nir Kaufman
 
PDF
Angularjs - Unit testing introduction
Nir Kaufman
 
PDF
Angular2 workshop
Nir Kaufman
 
PDF
Webstorm
Nir Kaufman
 
PDF
Angularjs - lazy loading techniques
Nir Kaufman
 
PDF
Webpack and angularjs
Nir Kaufman
 
PDF
AngularJS - Services
Nir Kaufman
 
PDF
Angular js - 10 reasons to choose angularjs
Nir Kaufman
 
PDF
Angular Promises and Advanced Routing
Alexe Bogdan
 
PDF
Angular js routing options
Nir Kaufman
 
PDF
Angular2 - getting-ready
Nir Kaufman
 
PDF
Functional Reactive Angular 2
Tomasz Bak
 
PDF
AngularJS performance & production tips
Nir Kaufman
 
Redux with angular 2 - workshop 2016
Nir Kaufman
 
Managing state in Angular 1.x with Redux
500Tech
 
Angular2 & ngrx/store: Game of States
Oren Farhi
 
Data Structures in javaScript 2015
Nir Kaufman
 
Up & running with ECMAScript6
Nir Kaufman
 
Solid angular
Nir Kaufman
 
Angular Pipes Workshop
Nir Kaufman
 
How Angular2 Can Improve Your AngularJS Apps Today!
Nir Kaufman
 
Angularjs - Unit testing introduction
Nir Kaufman
 
Angular2 workshop
Nir Kaufman
 
Webstorm
Nir Kaufman
 
Angularjs - lazy loading techniques
Nir Kaufman
 
Webpack and angularjs
Nir Kaufman
 
AngularJS - Services
Nir Kaufman
 
Angular js - 10 reasons to choose angularjs
Nir Kaufman
 
Angular Promises and Advanced Routing
Alexe Bogdan
 
Angular js routing options
Nir Kaufman
 
Angular2 - getting-ready
Nir Kaufman
 
Functional Reactive Angular 2
Tomasz Bak
 
AngularJS performance & production tips
Nir Kaufman
 
Ad

Similar to redux and angular - up and running (20)

PDF
Angular2 and Redux - up & running - Nir Kaufman - Codemotion Amsterdam 2016
Codemotion
 
PDF
React state managmenet with Redux
Vedran Blaženka
 
PDF
Understanding redux
David Atchley
 
PPTX
Redux training
dasersoft
 
PPTX
Getting started with Redux js
Citrix
 
PDF
The evolution of redux action creators
George Bukhanov
 
PPTX
React redux
Ramy ElBasyouni
 
PPTX
Maintaining sanity in a large redux app
Nitish Kumar
 
PDF
Materi Modern React Redux Power Point.pdf
exiabreak
 
PDF
Prescribing RX Responsibly
Nareg Khoshafian
 
PDF
[Codecamp 2016] Going functional with flyd and react
gcazaciuc
 
PDF
State of the state
Anton Korzunov
 
PDF
React & Redux
Federico Bond
 
PDF
Unidirectional Data Flow Architecture (Redux) in Swift
Seyhun AKYUREK
 
PDF
From mvc to redux: 停看聽
Jeff Lin
 
PDF
Intro to Redux | DreamLab Academy #3
DreamLab
 
PDF
Reactивная тяга
Vitebsk Miniq
 
PDF
Introduction to Redux
Ignacio Martín
 
PPTX
STATE MANAGEMENT IN REACT [Autosaved].pptx
siddheshjadhav919123
 
PDF
ReactiveCocoa in Practice
Outware Mobile
 
Angular2 and Redux - up & running - Nir Kaufman - Codemotion Amsterdam 2016
Codemotion
 
React state managmenet with Redux
Vedran Blaženka
 
Understanding redux
David Atchley
 
Redux training
dasersoft
 
Getting started with Redux js
Citrix
 
The evolution of redux action creators
George Bukhanov
 
React redux
Ramy ElBasyouni
 
Maintaining sanity in a large redux app
Nitish Kumar
 
Materi Modern React Redux Power Point.pdf
exiabreak
 
Prescribing RX Responsibly
Nareg Khoshafian
 
[Codecamp 2016] Going functional with flyd and react
gcazaciuc
 
State of the state
Anton Korzunov
 
React & Redux
Federico Bond
 
Unidirectional Data Flow Architecture (Redux) in Swift
Seyhun AKYUREK
 
From mvc to redux: 停看聽
Jeff Lin
 
Intro to Redux | DreamLab Academy #3
DreamLab
 
Reactивная тяга
Vitebsk Miniq
 
Introduction to Redux
Ignacio Martín
 
STATE MANAGEMENT IN REACT [Autosaved].pptx
siddheshjadhav919123
 
ReactiveCocoa in Practice
Outware Mobile
 
Ad

More from Nir Kaufman (9)

PDF
Angular Dependency Injection
Nir Kaufman
 
PDF
Angular Prestige: Less-known API and techniques
Nir Kaufman
 
PDF
Angular CLI custom builders
Nir Kaufman
 
PDF
Electronic music 101 for developers
Nir Kaufman
 
PDF
Nestjs MasterClass Slides
Nir Kaufman
 
PDF
Angular EE - Special Workshop by Nir Kaufman
Nir Kaufman
 
PDF
Decorators in js
Nir Kaufman
 
PDF
Styling recipes for Angular components
Nir Kaufman
 
PDF
Introduction To Angular's reactive forms
Nir Kaufman
 
Angular Dependency Injection
Nir Kaufman
 
Angular Prestige: Less-known API and techniques
Nir Kaufman
 
Angular CLI custom builders
Nir Kaufman
 
Electronic music 101 for developers
Nir Kaufman
 
Nestjs MasterClass Slides
Nir Kaufman
 
Angular EE - Special Workshop by Nir Kaufman
Nir Kaufman
 
Decorators in js
Nir Kaufman
 
Styling recipes for Angular components
Nir Kaufman
 
Introduction To Angular's reactive forms
Nir Kaufman
 

Recently uploaded (20)

PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 

redux and angular - up and running