react js101

29
a JavaScript library for building UI REACT JS created by Facebook / Instagram Song YANG

Upload: song-yang

Post on 05-Apr-2017

153 views

Category:

Engineering


3 download

TRANSCRIPT

Page 1: React js101

a J a v a S c r i p t l i b r a r y f o r b u i l d i n g U I

REACT JScreated by Facebook / Instagram

Song YANG

Page 2: React js101

KEY CONCEPTS

▫︎ Just the UI

▫︎ Re-render everything on every change

▫︎ Virtual DOM

▫︎ Synthetic Events

▫︎ Component-centric view layer

2

Page 3: React js101

REACT JS is not a MVC framework

JUST UI

3

Page 4: React js101

ONLY CARES ABOUT THE UI

▫︎ Routers

▫︎Models

▫︎Bindings

▫︎Observers

▫︎ Templates

4

Page 5: React js101

BINDINGS / OBSERVERS

▫︎Must mutate Model to propagate changes to View

▫︎ Each mutation can trigger other observers (Run Loop / Digest Loop)

▫︎Can't use immutable data structures as your model

▫︎ Two-way bindings open Pandora’s box

▫︎No easy way of knowing how far-reaching a change in the reverse direction is going to be

5

Page 6: React js101

6

Page 7: React js101

RE-RENDER THE ENTIRE APP

ON EVERY CHANGE

7

Page 8: React js101

8

▫︎No observers

▫︎No magical data binding

▫︎No model dirty checking

▫︎No $apply() or $digest()

Makes things simple to reason about

Re-render

Page 9: React js101

Virtual DOM

9

Page 10: React js101

VIRTUAL DOM

10

▫︎ in-memory data structure (fast)

▫︎ JavaScript representation of DOM

nodes, totally separate from the

browser’s slow JavaScript/C++ DOM API

▫︎Makes server-side rendering possible

▫︎Most important…

Page 11: React js101

11

VIRTUAL DOM DIFFING

Page 12: React js101

12

▫︎Build new Virtual DOM tree

▫︎Diff with old one

▫︎Compute minimal set of changes

▫︎Put them in a queue

▫︎Batch render all changes to browser

Treat the DOM like a GPU!

ON EVERY UPDATE

Page 13: React js101

13

Render from Data to Virtual DOM is fast No string concatenation

Page 14: React js101

Synthetic Events

14

Page 15: React js101

15

▫︎React implements it's own event system

▫︎ a cross-browser wrapper around the browser's native event

▫︎ same interface as the browser's native event

Treat the DOM like a GPU!

Synthetic Events

Page 16: React js101

16

Talk is Cheap, show you the code

Page 17: React js101

17

JSX is a JavaScript syntax extension that looks similar to XML. You can use a simple JSX syntactic transform with React.

JSX

Page 18: React js101

18

Page 19: React js101

19

https://github.com/owenyang0/react-starter

git clone

Page 20: React js101

20

1 Rendering

Page 21: React js101

21

2 Components

Page 22: React js101

22

Page 23: React js101

23

3 Props

Page 24: React js101

24

Page 25: React js101

25

4 State

Page 26: React js101

26

Page 27: React js101

27

5 Composition

Page 28: React js101

28

Page 29: React js101

29

Thanks