how to use flux (pattern) in react?

Post on 15-Apr-2017

83 Views

Category:

Software

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Flux + React

Rick Mak May 2015

Provided to you by
Skygear.io
Open source development kit for mobile, web & IoT apps

One of the pain

DOM

Skygear.io

Direct DOM = painful = BUG

Skygear.io

Age of Backbone

Model View

Skygear.io

Works Great in small scale

Skygear.io

more Model; more View

Skygear.io

It is SLOW

Skygear.io

Let Optimise it

Skygear.io
Skygear.io

Say Hello to VirtualDOM

Skygear.io

Model Virtual DOM DOM

Interact with VirtualDOM

Data Data

Event Event

Skygear.io

setState will trigger render

Define your view

Skygear.io

React calculate the diff

• Set state will mark the red dot

• React will find out the blue dots

• Re-render with only the modified dom

Source: https://facebook.github.io/react/img/blog/react-diff-tree.png

Skygear.io

Fast without spaghetti

Skygear.io

Let focus on Logic

Skygear.io

State inconsistency

Very common in single page webapp

Skygear.io

State inconsistency

• Server sync not sync with client state

• item missing

• duplicate item

• State between client not sync

• State panic with poor internet

Skygear.io

Flux fix that

Skygear.io

It is a pattern

A pattern enforcing unidirectional data flow

Flux is not framework

Skygear.io

View

Action

Store

Dispatcher

Server

Skygear.io

Unidirectional data flow

• Faster debug

• Faster on boarding

• Faster iteration

• Less cascading effect

Skygear.io

Brought to you by Oursky

Build your mobile app fast skygear.io (open source)

top related