Introduction to Redux Header Eric W. Greene Microsoft Virtual Academy

Slides:



Advertisements
Similar presentations
Hands-On Microsoft Windows Server 2003 Administration Chapter 5 Administering File Resources.
Advertisements

UNIT-V The MVC architecture and Struts Framework.
Presented by Brian Griffin On behalf of Manu Goel Mohit Goel Nov 12 th, 2014 Building a dynamic GUI, configurable at runtime by backend tool.
Overview of JSP Technology. The need of JSP With servlets, it is easy to – Read form data – Read HTTP request headers – Set HTTP status codes and response.
Windows.Net Programming Series Preview. Course Schedule CourseDate Microsoft.Net Fundamentals 01/13/2014 Microsoft Windows/Web Fundamentals 01/20/2014.
NextGen Technology upgrade – Synerizip - Sandeep Kamble.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
JavaScript & jQuery the missing manual Chapter 11
Philly.NET Hands-on Labs JAVASCRIPT SERIES. July 9: JavaScript Syntax Visual Studio ◦Projects ◦Editors ◦Debugging ◦Script blocks ◦Minification and bundling.
NOTE: To change the image on this slide, select the picture and delete it. Then click the Pictures icon in the placeholder to insert your own image. WEB.
Lesley Bross, August 29, 2010 ArcGIS 10 add-in glossary.
Computing IV Visual C Introduction with OpenCV Example Xinwen Fu.
Appendix A Starting Out with Windows PowerShell™ 2.0.
ICONICS ActiveX ToolWorX V 6.1.
NOTE: To change the image on this slide, select the picture and delete it. Then click the Pictures icon in the placeholder to insert your own image. WEB.
1 Geospatial and Business Intelligence Jean-Sébastien Turcotte Executive VP San Francisco - April 2007 Streamlining web mapping applications.
TypeScript Allan da Costa Pinto Technical Evangelist Microsoft.
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
Flux & React Web Application Development Mark Repka, Rich McNeary, Steve Mueller.
Microsoft Visual Basic 2015 CHAPTER ONE Introduction to Visual Basic 2015 Programming.
Ext JS - Direct Bridging The Gap A DMSBT Presentation By Timothy Chandler.
Using React, Drupal and Google Chrome to build an interactive kiosk + + =
Building Azure Mobile Apps
Java Server Pages Can web pages be created specially for each user?
Introducing the Microsoft® .NET Framework
Node.js Modules Header Mastering Node.js, Part 2 Eric W. Greene
Building Desktop Apps with Node.js and Electron
Scripting - Client-side vs. Server-side Scripting
JavaScript and Ajax (Ajax Tutorial)
Application Architecture, Redux
Data Virtualization Tutorial: Introduction to SQL Script
Node.js Express Web Applications
Modules, Babel, RequireJS, Other JavaScript Module Systems
Modern Web: Single Page Applications
Google Web Toolkit Tutorial
Data Transport for Online & Offline Processing
Self Healing and Dynamic Construction Framework:
Data Virtualization Tutorial… CORS and CIS
Node.js Express Web Services
Game-Changing Features in ES2015
The Client/Server Database Environment
Haritha Dasari Josue Balandrano Coronel -
Data Virtualization Tutorial: JSON_TABLE Queries
Functions CIS 40 – Introduction to Programming in Python
9/13/2018 7:43 AM © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN.
PHP / MySQL Introduction
Not Sure how you Should React
SharePoint-Hosted Apps and JavaScript
Module 1: Getting Started
Angularjs Interview Questions and Answers By Hope Tutors.
Top Reasons to Choose Angular. Angular is well known for developing robust and adaptable Single Page Applications (SPA). The Application structure is.
Displaying Form Validation Info
Chapter 4: Threads.
CSE 154 Lecture 22: AJAX.
CIS16 Application Development – Programming with Visual Basic
Modern web applications
Lecture 1: Multi-tier Architecture Overview
Redux IVAN LOVRIĆ 1.
An Introduction to Software Architecture
Modern web applications
Flux your app via Redux Quick introduction of state management in JavaScript apps using Redux.
Form Validation, Part 2 (with jQuery, HTML5, and CSS)
Introduction of Week 11 Return assignment 9-1 Collect assignment 10-1
An Introduction to JavaScript
Introduce to Angular 6 Present by: Võ Văn Hào
Consuming Web Services with 2E Generated Objects
Running C# in the browser
Alexander Lemkin Functional React.
Presentation transcript:

Introduction to Redux Header Eric W. Greene Microsoft Virtual Academy 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