react + flux

31
React + Flux Daniel Werthén, Frontend at Viktklubb Consultant at Netlight

Upload: daniel-werthen

Post on 08-Jul-2015

519 views

Category:

Technology


2 download

DESCRIPTION

An overview of React and the ideas surrounding it, specifically in Flux.

TRANSCRIPT

Page 1: React + flux

React + FluxDaniel Werthén, Frontend at Viktklubb

Consultant at Netlight

Page 2: React + flux

React is not a mvc framework

2

Page 3: React + flux

Nor is it a templating engine

3

Page 4: React + flux

React is a library for creating UI

4

Page 5: React + flux

It treats UI as a function

5

AKA: Components

Page 6: React + flux

Data comes in, virtual DOM comes out

6

Page 7: React + flux

When the data changesre-render

7

Page 8: React + flux

Diff the next virtual DOM with the previous one

8

Page 9: React + flux

Update the real DOM with little to no

overhead

9

Page 10: React + flux

What makes UI development

difficult?

10

Page 11: React + flux

State is hard

11

Page 12: React + flux

State is hard

12

And UI means a lot of state

Page 13: React + flux

Even more so if it is mutable

13

Page 14: React + flux

And exponentially so if it changes over time

14

Page 15: React + flux

It is difficult to debug

15

Page 16: React + flux

Makes concurrency a nightmare

16

Page 17: React + flux

So what to do? Flux!

17

Page 18: React + flux

Flux is more of a pattern rather than a framework

18

Page 19: React + flux

Gather all state in one place

19

Page 20: React + flux

(In normalized form)

20

Page 21: React + flux

Apply transformations on this one true source of state

21

Page 22: React + flux

With an output that is the input of React

components

22

Page 23: React + flux

User input results in changed state

23

Page 24: React + flux

Which is tracked by

event callbacks

And then reflected as updates to the state[source]

24

Page 25: React + flux

That change is propagatedto the components sharing

the same state

25

Page 26: React + flux

Components sharing the same state are

completely de-coupled

26

Page 27: React + flux

Components are (properly)

composable

27

Page 28: React + flux

Uni-directional flow

28

[State]Stores

[UI]Components

[User input]Actions

Dispatcher

Page 29: React + flux

DEMO

29

Page 30: React + flux

QA?

30

Page 31: React + flux

React in short

It is very efficient!

No unneccessary DOM updates

Virtual event callbacks mapping

DOM independent

Easy server side rendering (RenderComponentToString)

Unit testing components with Jest

Works wonders with Browserify and NPM

31