Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building Modern Web Applications using React and Redux

Building Modern Web Applications using React and Redux

React and Redux are latest evolution in modern web application development. This talk covers the concepts and set of technologies of modern web application development.

Maxime Najim

May 18, 2017
Tweet

More Decks by Maxime Najim

Other Decks in Education

Transcript

  1. About Me • Software architect and a full stack web

    developer • Over 12 years experience building large, highly scalable and reliable web applications for companies like Yahoo!, Apple, Netflix, and Walmart • Co-author of the O'Reilly Media book entitled "Building Isomorphic JavaScript Apps” and an upcoming video series: “Universal JavaScript with React, Node, and Redux”. Publications Sr. Software Architect
 Walmart Global eCommerce September 2016 August 2017
  2. Action - Add to Cart State 1 State 2 State

    3 State N Action 1 Action 2 Action N
  3. The Problem of Modern Web Applications As an application grows

    it becomes harder to determine the overall state of the application and cumbersome to understand where updates are coming from.
  4. The Anatomy of a Client Application Data View Web App

    Events • Data: Server Data and Input • Display: A visual representation of the data • Event Handlers: User interactions
  5. The Anatomy of a Client Application Redux View Web App

    Events • Data: Server Data and Input • Display: A visual representation of the data • Event Handlers: User interactions
  6. The Anatomy of a Client Application Redux React Web App

    Events • Data: Server Data and Input • Display: A visual representation of the data • Event Handlers: User interactions
  7. Redux - 
 Basic Flow • Uni-directional data flow •

    Immutable single store • Action object describing what happened. • All state updates are performed by pure functions ref: http://slides.com/jenyaterpil/redux-from-twitter-hype-to-production#/9 (state, action) => state
  8. Redux - 
 Basic Flow • An action is dispatched

    (often in response to user interaction). • The root reducer function is called with the current state and the dispatched action. • It then returns the new state. • React app retrieves the updated state and re-renders (state, action) => state Action Event
  9. Redux - 
 Basic Flow • An action is dispatched

    (often in response to user interaction). • The root reducer function is called with the current state and the dispatched action. • It then returns the new state. • React app retrieves the updated state and re-renders (state, action) => state State Action
  10. Redux - 
 Basic Flow • An action is dispatched

    (often in response to user interaction). • The root reducer function is called with the current state and the dispatched action. • It then returns the new state. • View retrieves the updated state and re-renders (state, action) => state State
  11. Redux - 
 Async Flow • Action creator can have

    logic for communicating with backend APIs • Middleware provides third-party extension point that can be added to redux Redux Side Effects
  12. Redux - 
 Async Flow • An event in the

    UI causes and action created to be invoked
  13. Redux - 
 Async Flow • An event in the

    UI causes and action created to be invoked • A function is returned by the action creator
  14. Redux - 
 Async Flow • An event in the

    UI causes and action created to be invoked • A function is returned by the action creator • Middleware calls the function
  15. Redux - 
 Async Flow • Dispatches a “Request Started”

    action and calls the API. • Once a response is returned from the API call.
  16. Redux - 
 Async Flow • Dispatch a “Request Started”

    action and call the API • A response is returned from the API call • Dispatch a “Request Succeeded” action
  17. Redux - 
 Async Flow • Dispatch a “Request Started”

    action and call the API • A response is returned from the API call • Dispatch a “Request Succeeded” action
  18. Redux - 
 Async Flow • Dispatch a “Request Started”

    action and call the API • A response is returned from the API call • Dispatch a “Request Succeeded” action
  19. Redux - 
 Async Flow • Dispatch a “Request Started”

    action and call the API • A response is returned from the API call • Dispatch a “Request Succeeded” action
  20. Web Browser Rendering Engine 
 
 (HTML, CSS) Scripting Engine

    (JavaScript) Browser APIs (Document, Window, Navigator)
  21. Web Browser Rendering Engine 
 
 (HTML, CSS) Scripting Engine

    Browser APIs (Document, Window, Navigator) React.js Components Data Virtual DOM minimal set of
 real DOM 
 mutations
  22. Redux - 
 Basic Flow • Uni-directional data flow •

    Immutable single store • Action object describing what happened. • All state updates are performed by pure functions store.dispatch() store.subscribe(…)
  23. Container/Presentational Components Presentational Components Container Components Purpose How things look

    
 (markup, styles) How things work 
 (data fetching, state updates) Aware of Redux No Yes To read data Read data from props Subscribe to Redux state To change data Invoke callbacks from props Dispatch Redux actions ref: http://redux.js.org/docs/basics/UsageWithReact.html
  24. Hello World with node.js http://www.modulecounts.com/ $ node > console.log('Hello World');

    Hello World Interactive Shell Execute JavaScript file $ echo "console.log('Hello World');" > hello.js $ node hello.js Hello World
  25. Creating a package.json { "name": "my-app", "version": "0.1.0", "dependencies": {

    … }, "devDependencies": { … }, "scripts": { … } } package.json
  26. Creating a package.json package.json { "name": "my-app", "version": "0.1.0", "dependencies":

    { "express": "^4.15.2", "react": "^15.4.2", "react-dom": “^15.4.2”, "react-redux": "^5.0.2", "react-router": "^3.0.2", "redux": "^3.6.0", "redux-thunk": "^2.2.0" }, "devDependencies": { … }, "scripts": { $ npm install react react-dom … —save Run
  27. Creating a package.json package.json { "name": "my-app", "version": "0.1.0", "dependencies":

    { … }, "devDependencies": { "babel-core": "^6.24.0", "babel-loader": "^6.4.1", "babel-preset-es2015": "^6.24.0", "babel-preset-react": "^6.23.0", "webpack": "^2.3.2" }, "scripts": { … } $ npm install babel-core babel-loader
 .. webpack --save-dev Run
  28. Creating a package.json { "name": "my-app", "version": "0.1.0", "dependencies": {

    … }, "devDependencies": { … }, "scripts": { "start": "node server/index.js”, "build": "webpack --config webpack.config.js" } } package.json
  29. node_modules folder webpack.config.js var config = { entry:"/index.jsx", output: {

    filename: "bundle.js" }, module: { loaders: [{ test: /\.jsx?$/, exclude: /node_modules/, loader: 'babel-loader', include: “client”, }] } };