flux and redux

30
Flux & Redux Morgan Cheng

Upload: morgan-cheng

Post on 20-Jan-2017

88 views

Category:

Engineering


0 download

TRANSCRIPT

Page 1: Flux and redux

Flux & ReduxMorgan Cheng

Page 2: Flux and redux

2006 2010 2013 2015

Page 3: Flux and redux

Problem

Page 4: Flux and redux

More Problem

Page 5: Flux and redux

So, Flux is THE ONE?

Page 6: Flux and redux

“React + Flux can do in just 137 lines what jQuery can do in 10!”

“What about thousands of lines of code”

Page 7: Flux and redux

“React + Flux can do in just 137 lines what jQuery can do in 10!”

“What about thousands of lines of code”

Page 8: Flux and redux

Predictable

Page 9: Flux and redux

UI = f(state)

Page 10: Flux and redux

UI = f(state)

Page 11: Flux and redux

Uni-Direction Data Flow

Page 12: Flux and redux
Page 13: Flux and redux

Game Time: Let’s Play Flux

Page 14: Flux and redux

Drawbacks of Flux• Inter-dependency among multiple stores

• Hard to support Server Side Rendering

• Hard to do hot-reloading

Page 15: Flux and redux

Flux is just an idea

Page 16: Flux and redux

So Many Weapons

Page 17: Flux and redux

Redux is Flux

Page 18: Flux and redux

Redux = Reducers + Flux

Page 19: Flux and redux

Reducer

(accumulation, input) => new_accumulation

(state, action) => new_state

Page 20: Flux and redux
Page 21: Flux and redux

What If I Told YouThe State is Immutable

Page 22: Flux and redux

Three Principles of Redux• Single Source of Truth

• State is read-only

• Changes are made with pure functions

Page 23: Flux and redux

Game Time: Let’s Play Redux

Page 24: Flux and redux

Encapsulation

Component

View

Reducer

Actions

JavaScript

SCSS/CSS

Images

Page 25: Flux and redux

Code Demo Time

Page 26: Flux and redux
Page 27: Flux and redux
Page 28: Flux and redux

Convention is NOT enoughConstraint Matters!

Page 29: Flux and redux

What’s your role?

Page 30: Flux and redux

ThanksAny Questions?