react, flux and more (p1)

44
React, Flux and… more (p1)

Upload: tuanpa206

Post on 16-Apr-2017

139 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: React, Flux and more (p1)

React, Flux and… more (p1)

Page 2: React, Flux and more (p1)

Content Core Technologies React Flux Demo

Page 3: React, Flux and more (p1)

Content Core Technologies React Flux Demo

Page 4: React, Flux and more (p1)

Core Technologies

Page 5: React, Flux and more (p1)
Page 6: React, Flux and more (p1)

Node Server-side JS Uses the V8 Engine Includes npm package manager

Page 7: React, Flux and more (p1)

Browserify

Use Node modules in the browser Bundle dependencies

Page 8: React, Flux and more (p1)

React

Component Library Simple composition Utilizes virtual DOM Can render on client and server

Page 9: React, Flux and more (p1)

React router Nested views map to nested routes Declarative Used at Facebook Inspired by Ember

Page 10: React, Flux and more (p1)

Flux

Uni-directional data flows More a pattern than a library

Page 11: React, Flux and more (p1)
Page 12: React, Flux and more (p1)

Gulp

Task runner Rich plugin ecosystem Stream-based

Page 13: React, Flux and more (p1)

Summary Node & npm : packages React: Components React-router: Routing Flux: Data flows Browserify: Bundler Gulp: Builds

Page 14: React, Flux and more (p1)

React

Page 15: React, Flux and more (p1)

What is React? React (sometimes styled React.js or ReactJS) is an open-source JavaScript library providing a view for data rendered as HTML.

Page 16: React, Flux and more (p1)

What is React? React isn't an MVC framework React doesn't use templates Reactive updates are dead simple

Page 17: React, Flux and more (p1)

What is React? Try to keep an open mind. Unidirectional flow. No two-way binding. Inline styles can be good. JavaScript and HTML belong in the same file

Page 18: React, Flux and more (p1)
Page 19: React, Flux and more (p1)

Why React?

“We built React to solve one problem: building large applications with data that changes over time.”

Page 20: React, Flux and more (p1)

Why React? Fast Composable Pluggable Isomorphic Friendly Simple Battle Proven

Page 21: React, Flux and more (p1)

Virtual Dom

Compare DOM’s current state to desired new state. Update the DOM in the most efficient way

Page 22: React, Flux and more (p1)
Page 23: React, Flux and more (p1)
Page 24: React, Flux and more (p1)

Top-Level API

React.createClass React.createElement React.DOM React.Children

Page 25: React, Flux and more (p1)

Component API

setState setProps replaceState forceUpdate isMounted replaceProps

Page 26: React, Flux and more (p1)

Component API

render() : the render() method is required.

Page 27: React, Flux and more (p1)

ReactDOM

ReactDOM.unmountComponentAtNode ReactDOM.render ReactDOM.findDOMNode

Page 28: React, Flux and more (p1)

The life of a component

Page 29: React, Flux and more (p1)

Props & State

Props : pass data to child components State : data in controller view

Page 30: React, Flux and more (p1)

Initial State

getInitialState

Page 31: React, Flux and more (p1)

Default prop values

getDefaultProps

Page 32: React, Flux and more (p1)

JSX “HTML” in JavaScript Differences: className, htmlFor Compiles to JavaScript Optional

Page 33: React, Flux and more (p1)

Lifecycle Methods

componentWillMount componentDidMount componentWillReceiveProps shouldComponentUpdate componentWillUpdate componentDidUpdate componentWillUnmount

Page 34: React, Flux and more (p1)

componentWillMount

When Before initial render, both client and server. Why Good spot to set initial state.

Page 35: React, Flux and more (p1)

componentDidMount

When After render. Why Access DOM, integrate with frameworks, set timers, AJAX requests.

Page 36: React, Flux and more (p1)

componentWillReceiveProp

When When receiving new props. Not called on initial render. Why Set state before a render.

Page 37: React, Flux and more (p1)

shouldComponentUpdate

When Before render when new props or state are being received. Not called on initial render. Why Performance. Return false to void unnecessary re-renders.

Page 38: React, Flux and more (p1)

componentWillUpdate

When Immediately before rendering when new props or state are being received. Not called on initial render. Why Prepare for an update.

Page 39: React, Flux and more (p1)

componentDidUpdate

When After component's updates are flushed to the DOM. Not called for the initial render. Why Work with the DOM after an update.

Page 40: React, Flux and more (p1)

componentWillUnmount

When Immediately before component is removed from the DOM Why Cleanup.

Page 41: React, Flux and more (p1)

propTypes - Validate props propTypes: { author: React.PropTypes.object.isRequired, onSave: React.PropTypes.func.isRequired, validate: React.PropTypes.func.isRequired, }

- Development vs. Production Mode - Minified version is for production.

Page 42: React, Flux and more (p1)

Mixins For cross-cutting concerns Share code between multiple components

Page 43: React, Flux and more (p1)

Statics

Page 44: React, Flux and more (p1)

THANK YOU (to be continued …)