SlideShare a Scribd company logo
1 of 33
Header
Microsoft Virtual Academy
Introduction to Redux
Eric W. Greene
Produced by
Course Overview
 Why Redux?
 Three Principles of Redux
 Essential JavaScript Concepts
 Reducer Functions
 Working with Stores
 Combining Reducers
 Integration with React and Asynchronous Operations
Why Redux?
 Managing state in JavaScript applications is very challenging
 Redux employs a predictable state container to simplify state
management
 Execution of an application is an initial state followed by a series of
actions
Why Redux?
 Each action reduces the state to a new predictable state, to which the
application user interface transitions
 A state container, known as store, contains the reduction logic
implemented as pure functions as well as the last reduced (current)
state
Three Principles of Redux
 To enable state changes to be predictable, the following constraints
applied to state changes
 Single Source of Truth
 State is Read-Only
 Changes are made with Pure Functions
Single Source of Truth
 Following the pattern of Flux, all data flows through a Redux system in
a unidirectional matter
 All changes to the state comes from actions applied to the state, and
all actions are funneled into Redux
 No part of the system can ever receive data from two sources
 Additionally, the state managed by Redux is the state of the whole
application (with minor exceptions, such as form control entry)
State is Read-Only
 State can never be mutated
 New states are produced by applying an action to the current state
(known as reduction) from which a new state object is produced
 Immutable programming techniques need to be utilized
Changes are made with Pure Functions
 Pure functions accept inputs, and using only those inputs produce a
single output
 The function produces no side effects
 Many pure functions can be composed together to process different
parts of the state tree
Definition of Redux
 From the Redux website, "Redux is a predictable state container for
JavaScript apps."
 Predictable – state changes follow the three principles
 State – the application's data, including data related to the UI itself
 Container – Redux is the container which applies actions to the pure
reducer functions to return a new state
 Redux has been designed for JavaScript applications
Differences from Flux
 While Redux and Flux share similar concepts and principles, there are
some differences
 Flux differentiates between the dispatcher and store, this is because
Flux supports multiple stores
 Redux limits the application to one store which means the store and
dispatcher can be combined into one dispatcher-store
 This dispatcher-store is created by Redux's createStore function
Development Environment
 Visual Studio Code + Google Chrome – using the Chrome extension
for Visual Studio Code, in editor debugging of TypeScript code will be
available
 REST Server provided by json-server, Web Server provided by browser-
sync
 TypeScript is used for module support and strong-typing
Development Environment
 Dynamic Module Loading with SystemJS
 ES2015 code is not transpiled to ES5.1, it will run as ES2015 natively
 Node.js powers the development tooling
Setup Development Environment
Essential JavaScript and Web Browser API Concepts
 Object.assign
 Immutable Array Functions
 Function Parameter Default Values
 Arrow Functions
 Destructuring, Spread Operator, and Rest Operator
 Fetch & Promises
 ES2015 Modules
Essential JavaScript Concepts
 Object.assign – used to copy properties from one object to another
 Immutable Array Functions – produce a new array instead of mutating
an existing array
 Function Parameter Default Values – used to initialize state when the
application loads
 Arrow Functions – commonly used when lexical this or a simpler syntax
is desired
Essential JavaScript Concepts
 Destructuring, Spreads, and Rest – makes working with properties
easier
 Fetch & Promises – Fetch is the new API for making REST service calls
instead of libraries such as jQuery or using the XHR object directly
 Fetch is not a standard, but hopefully will be soon
 Promises are an ES2015 standard with wide support
Essential JavaScript Concepts
 ES2015 Modules – Not supported natively, but TypeScript will transpile
to UMD modules to be loaded by SystemJS
 Eventually, ES2015 modules (static and dynamic – through SystemJS)
should be available natively
Essential JavaScript Concepts
Reducer Functions
 Follows the pattern of the reduce function available on the Array
prototype in JavaScript
 Receives the current state and an action, the function produces a new
state based upon the type of action, and its associated data
 Pure function – output results from inputs only, no side-effects
 Should be configured to create an initial state during the first run
Reducer Functions
Working with Stores
 Stores are the container for applying the action to the state using the
reducer function, and they contain the current state
 Created with the createStore function
 The first parameter is the reducer function
 The second parameter is an optional initial state, if this is not provided
the default state initialized by the reducer function will be used on the
first run-through
Store Initialization
 When a store is created, the reducer function is executed with no
action allowing the default parameter value and the reducer functions
to initialize the application state
 If an initial state is passed into the createStore function, the initial
state is passed in when the store is created
Handling Actions with the Store
 Actions are sent to the store using the dispatch function
 The dispatch function accepts the action object as an argument
 The action object must have a type property to identify what the
action is, additional properties with other relevant data may be
specified as well
Distributing the New State
 To distribute the new state produced from a dispatched action, a
publisher/subscriber model is used through a subscribe function
available on the store
 When actions are dispatched, they are processed by the reducer
producing a new state, then all of the subscriber functions are invoked
so they can process the new state
 The new state is retrieved in the subscriber function through the
getState function on the store
Working with Stores
Combining Reducers
 The state tree for an application can grow quickly especially when
considering the first principle of Redux which is the entire state of the
application is stored in one object
 Writing a single reducer function for the whole state tree results in a
long, bloated and difficult to maintain function
Combining Reducers
 Commonly, reducer functions will be divided into multiple reducer
functions with each function being responsible for one branch of the
state tree
 Redux provides a combineReducers function to combine these
multiple reducer functions into a single function for the store
Combining Reducers
Integration with React and Asynchronous Programming
 Redux works great with React, but Redux is not limited to only working
React
 Nevertheless, the React/Redux combination is so popular there are
special libraries for tying the two together and there are lots of
resources online which explore this common combination of libraries
 Asynchronous programming introduces additional complexities to
managing state
Integration with React
 This course will not focus on the react-redux available here:
https://github.com/reactjs/react-redux
 Instead, this course will connect Redux into React using appropriate
coding patterns
 The store will be passed in as property to the top level state
component of the React UI
 React component lifecycle functions will be used to interact with the
store's functionality
Asynchronous Programming
 Asynchronous Redux programming appears difficult at first, but really
its quite easy
 The key is to understand how state and asynchronous operations work
together
 Asynchronous operations have two states:
 Pending Request State
 Fulfilled Request State
Integration with React and Asynchronous Operations
Conclusion
 Redux, inspired by Flux, improves the management of state in
JavaScript applications
 Its built on three principles: single source of truth, immutable state,
and pure reducer functions
 Redux provides the container for applying the actions to produce new
states based upon the logic of the reducer functions
 Reducer functions can work on different parts of the state tree and be
combined together

More Related Content

Similar to downloads_introduction to redux.pptx

React JS Interview Question & Answer
React JS Interview Question & AnswerReact JS Interview Question & Answer
React JS Interview Question & AnswerMildain Solutions
 
Redux State Management System A Comprehensive Review
Redux State Management System A Comprehensive ReviewRedux State Management System A Comprehensive Review
Redux State Management System A Comprehensive Reviewijtsrd
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react jsStephieJohn
 
Advanced Redux architecture - WHAT/WHEN/WHY/HOW
Advanced Redux architecture - WHAT/WHEN/WHY/HOWAdvanced Redux architecture - WHAT/WHEN/WHY/HOW
Advanced Redux architecture - WHAT/WHEN/WHY/HOWMateusz Bosek
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
Basic Fundamental of Redux
Basic Fundamental of ReduxBasic Fundamental of Redux
Basic Fundamental of ReduxInnovationM
 
React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥Remo Jansen
 
Presentation on "An Introduction to ReactJS"
Presentation on "An Introduction to ReactJS"Presentation on "An Introduction to ReactJS"
Presentation on "An Introduction to ReactJS"Flipkart
 
React js programming concept
React js programming conceptReact js programming concept
React js programming conceptTariqul islam
 
React.js and Redux overview
React.js and Redux overviewReact.js and Redux overview
React.js and Redux overviewAlex Bachuk
 
Redux and context api with react native app introduction, use cases, implemen...
Redux and context api with react native app introduction, use cases, implemen...Redux and context api with react native app introduction, use cases, implemen...
Redux and context api with react native app introduction, use cases, implemen...Katy Slemon
 
A React Journey
A React JourneyA React Journey
A React JourneyLinkMe Srl
 
Introduction to ReactJS UI Web Dev .pptx
Introduction to ReactJS UI Web Dev .pptxIntroduction to ReactJS UI Web Dev .pptx
Introduction to ReactJS UI Web Dev .pptxSHAIKIRFAN715544
 
Getting started with Redux js
Getting started with Redux jsGetting started with Redux js
Getting started with Redux jsCitrix
 
Introduction to React JS.pptx
Introduction to React JS.pptxIntroduction to React JS.pptx
Introduction to React JS.pptxSHAIKIRFAN715544
 

Similar to downloads_introduction to redux.pptx (20)

React-JS.pptx
React-JS.pptxReact-JS.pptx
React-JS.pptx
 
Reducers+flux=redux
Reducers+flux=reduxReducers+flux=redux
Reducers+flux=redux
 
React JS Interview Question & Answer
React JS Interview Question & AnswerReact JS Interview Question & Answer
React JS Interview Question & Answer
 
Redux State Management System A Comprehensive Review
Redux State Management System A Comprehensive ReviewRedux State Management System A Comprehensive Review
Redux State Management System A Comprehensive Review
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react js
 
Advanced Redux architecture - WHAT/WHEN/WHY/HOW
Advanced Redux architecture - WHAT/WHEN/WHY/HOWAdvanced Redux architecture - WHAT/WHEN/WHY/HOW
Advanced Redux architecture - WHAT/WHEN/WHY/HOW
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
Basic Fundamental of Redux
Basic Fundamental of ReduxBasic Fundamental of Redux
Basic Fundamental of Redux
 
React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥
 
Presentation on "An Introduction to ReactJS"
Presentation on "An Introduction to ReactJS"Presentation on "An Introduction to ReactJS"
Presentation on "An Introduction to ReactJS"
 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
 
React.js and Redux overview
React.js and Redux overviewReact.js and Redux overview
React.js and Redux overview
 
Copy of React_JS_Notes.pdf
Copy of React_JS_Notes.pdfCopy of React_JS_Notes.pdf
Copy of React_JS_Notes.pdf
 
Redux essentials
Redux essentialsRedux essentials
Redux essentials
 
Redux and context api with react native app introduction, use cases, implemen...
Redux and context api with react native app introduction, use cases, implemen...Redux and context api with react native app introduction, use cases, implemen...
Redux and context api with react native app introduction, use cases, implemen...
 
Redux Like Us
Redux Like UsRedux Like Us
Redux Like Us
 
A React Journey
A React JourneyA React Journey
A React Journey
 
Introduction to ReactJS UI Web Dev .pptx
Introduction to ReactJS UI Web Dev .pptxIntroduction to ReactJS UI Web Dev .pptx
Introduction to ReactJS UI Web Dev .pptx
 
Getting started with Redux js
Getting started with Redux jsGetting started with Redux js
Getting started with Redux js
 
Introduction to React JS.pptx
Introduction to React JS.pptxIntroduction to React JS.pptx
Introduction to React JS.pptx
 

Recently uploaded

Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncssuser2ae721
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...121011101441
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 

Recently uploaded (20)

Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 

downloads_introduction to redux.pptx

  • 1. Header Microsoft Virtual Academy Introduction to Redux Eric W. Greene Produced by
  • 2. Course Overview  Why Redux?  Three Principles of Redux  Essential JavaScript Concepts  Reducer Functions  Working with Stores  Combining Reducers  Integration with React and Asynchronous Operations
  • 3. Why Redux?  Managing state in JavaScript applications is very challenging  Redux employs a predictable state container to simplify state management  Execution of an application is an initial state followed by a series of actions
  • 4. Why Redux?  Each action reduces the state to a new predictable state, to which the application user interface transitions  A state container, known as store, contains the reduction logic implemented as pure functions as well as the last reduced (current) state
  • 5. Three Principles of Redux  To enable state changes to be predictable, the following constraints applied to state changes  Single Source of Truth  State is Read-Only  Changes are made with Pure Functions
  • 6. Single Source of Truth  Following the pattern of Flux, all data flows through a Redux system in a unidirectional matter  All changes to the state comes from actions applied to the state, and all actions are funneled into Redux  No part of the system can ever receive data from two sources  Additionally, the state managed by Redux is the state of the whole application (with minor exceptions, such as form control entry)
  • 7. State is Read-Only  State can never be mutated  New states are produced by applying an action to the current state (known as reduction) from which a new state object is produced  Immutable programming techniques need to be utilized
  • 8. Changes are made with Pure Functions  Pure functions accept inputs, and using only those inputs produce a single output  The function produces no side effects  Many pure functions can be composed together to process different parts of the state tree
  • 9. Definition of Redux  From the Redux website, "Redux is a predictable state container for JavaScript apps."  Predictable – state changes follow the three principles  State – the application's data, including data related to the UI itself  Container – Redux is the container which applies actions to the pure reducer functions to return a new state  Redux has been designed for JavaScript applications
  • 10. Differences from Flux  While Redux and Flux share similar concepts and principles, there are some differences  Flux differentiates between the dispatcher and store, this is because Flux supports multiple stores  Redux limits the application to one store which means the store and dispatcher can be combined into one dispatcher-store  This dispatcher-store is created by Redux's createStore function
  • 11. Development Environment  Visual Studio Code + Google Chrome – using the Chrome extension for Visual Studio Code, in editor debugging of TypeScript code will be available  REST Server provided by json-server, Web Server provided by browser- sync  TypeScript is used for module support and strong-typing
  • 12. Development Environment  Dynamic Module Loading with SystemJS  ES2015 code is not transpiled to ES5.1, it will run as ES2015 natively  Node.js powers the development tooling
  • 14. Essential JavaScript and Web Browser API Concepts  Object.assign  Immutable Array Functions  Function Parameter Default Values  Arrow Functions  Destructuring, Spread Operator, and Rest Operator  Fetch & Promises  ES2015 Modules
  • 15. Essential JavaScript Concepts  Object.assign – used to copy properties from one object to another  Immutable Array Functions – produce a new array instead of mutating an existing array  Function Parameter Default Values – used to initialize state when the application loads  Arrow Functions – commonly used when lexical this or a simpler syntax is desired
  • 16. Essential JavaScript Concepts  Destructuring, Spreads, and Rest – makes working with properties easier  Fetch & Promises – Fetch is the new API for making REST service calls instead of libraries such as jQuery or using the XHR object directly  Fetch is not a standard, but hopefully will be soon  Promises are an ES2015 standard with wide support
  • 17. Essential JavaScript Concepts  ES2015 Modules – Not supported natively, but TypeScript will transpile to UMD modules to be loaded by SystemJS  Eventually, ES2015 modules (static and dynamic – through SystemJS) should be available natively
  • 19. Reducer Functions  Follows the pattern of the reduce function available on the Array prototype in JavaScript  Receives the current state and an action, the function produces a new state based upon the type of action, and its associated data  Pure function – output results from inputs only, no side-effects  Should be configured to create an initial state during the first run
  • 21. Working with Stores  Stores are the container for applying the action to the state using the reducer function, and they contain the current state  Created with the createStore function  The first parameter is the reducer function  The second parameter is an optional initial state, if this is not provided the default state initialized by the reducer function will be used on the first run-through
  • 22. Store Initialization  When a store is created, the reducer function is executed with no action allowing the default parameter value and the reducer functions to initialize the application state  If an initial state is passed into the createStore function, the initial state is passed in when the store is created
  • 23. Handling Actions with the Store  Actions are sent to the store using the dispatch function  The dispatch function accepts the action object as an argument  The action object must have a type property to identify what the action is, additional properties with other relevant data may be specified as well
  • 24. Distributing the New State  To distribute the new state produced from a dispatched action, a publisher/subscriber model is used through a subscribe function available on the store  When actions are dispatched, they are processed by the reducer producing a new state, then all of the subscriber functions are invoked so they can process the new state  The new state is retrieved in the subscriber function through the getState function on the store
  • 26. Combining Reducers  The state tree for an application can grow quickly especially when considering the first principle of Redux which is the entire state of the application is stored in one object  Writing a single reducer function for the whole state tree results in a long, bloated and difficult to maintain function
  • 27. Combining Reducers  Commonly, reducer functions will be divided into multiple reducer functions with each function being responsible for one branch of the state tree  Redux provides a combineReducers function to combine these multiple reducer functions into a single function for the store
  • 29. Integration with React and Asynchronous Programming  Redux works great with React, but Redux is not limited to only working React  Nevertheless, the React/Redux combination is so popular there are special libraries for tying the two together and there are lots of resources online which explore this common combination of libraries  Asynchronous programming introduces additional complexities to managing state
  • 30. Integration with React  This course will not focus on the react-redux available here: https://github.com/reactjs/react-redux  Instead, this course will connect Redux into React using appropriate coding patterns  The store will be passed in as property to the top level state component of the React UI  React component lifecycle functions will be used to interact with the store's functionality
  • 31. Asynchronous Programming  Asynchronous Redux programming appears difficult at first, but really its quite easy  The key is to understand how state and asynchronous operations work together  Asynchronous operations have two states:  Pending Request State  Fulfilled Request State
  • 32. Integration with React and Asynchronous Operations
  • 33. Conclusion  Redux, inspired by Flux, improves the management of state in JavaScript applications  Its built on three principles: single source of truth, immutable state, and pure reducer functions  Redux provides the container for applying the actions to produce new states based upon the logic of the reducer functions  Reducer functions can work on different parts of the state tree and be combined together