SlideShare a Scribd company logo
@tomchentwhttp://goo.gl/j9M1Nr
REACT.JS TW MEETUP #5
FLUX ANALYSIS
http://www.qrcode-monkey.com
@tomchentwhttp://goo.gl/j9M1Nr
TOM CHEN
REACT/FLUX ENTHUSIAST
JAVASCRIPT EXPERT
@tomchentw
FLUX 解決什麼問題
@tomchentwhttp://goo.gl/j9M1Nr
flux 解決什麼問題
跨元件溝通

同階層或跨好幾個階層

資料相依性

維護性
@tomchentw
FLUX ⽤用什麼⽅方式解決
@tomchentwhttp://goo.gl/j9M1Nr
flux ⽤用什麼⽅方式解決
資料流

明確定義資料流向

單向資料流

唯⼀一真相
@tomchentw
初探各種 FLUX 實作
@tomchentwhttp://goo.gl/j9M1Nr
初探各種 flux 實作
flux 只是⼀一個「概念」

應⽤用情境不同

pure client side

client side + routing

server side + routing = isomorphic

封裝⽅方式不同
@tomchentw
跟著FLUX去旅⾏行
@tomchentwhttp://goo.gl/j9M1Nr
圖解資料流
以臉書使⽤用者按讚為例
@tomchentwhttp://goo.gl/j9M1Nr
圖解資料流
以臉書使⽤用者按讚為例
@tomchentwhttp://goo.gl/j9M1Nr
圖解資料流
以臉書使⽤用者按讚為例
@tomchentwhttp://goo.gl/j9M1Nr
圖解資料流
以臉書使⽤用者按讚為例
@tomchentwhttp://goo.gl/j9M1Nr
圖解資料流
以臉書使⽤用者按讚為例
@tomchentw
跟著FLUX去旅⾏行
OVER THE WEB
@tomchentwhttp://goo.gl/j9M1Nr
圖解資料流
以臉書使⽤用者按讚為例
@tomchentwhttp://goo.gl/j9M1Nr
圖解資料流
以臉書使⽤用者按讚為例
@tomchentwhttp://goo.gl/j9M1Nr
圖解資料流
以臉書使⽤用者按讚為例
@tomchentwhttp://goo.gl/j9M1Nr
圖解資料流
以臉書使⽤用者按讚為例
@tomchentwhttp://goo.gl/j9M1Nr
圖解資料流
以臉書使⽤用者按讚為例
@tomchentw
回到應⽤用情境
@tomchentwhttp://goo.gl/j9M1Nr
應⽤用情境不同
pure client side

client side + routing

server side + routing = isomorphic
@tomchentw
簡單分類三種 FLUX 實作
@tomchentwhttp://goo.gl/j9M1Nr
需要考慮什麼問題

不需考慮什麼問題

實際應⽤用例⼦子

對應flux實作
@tomchentw
PURE CLIENT SIDE
@tomchentwhttp://goo.gl/j9M1Nr
需要考慮什麼問題
觸發Action時機

componentDidMount

跟API要資料

放在action內

放在store getter function內

資料回來後

再次觸發成功或失敗的Action

直接改store值,然後emit change
@tomchentwhttp://goo.gl/j9M1Nr
不需考慮什麼問題
伺服器⼀一般設定

在index.html引⼊入⼀一個傳統的script tag,收⼯工

伺服器路由設定

Singleton Issue
@tomchentwhttp://goo.gl/j9M1Nr
實際應⽤用例⼦子
Facebook Power Editor

http://conf.reactjs.com/schedule.html#flux-panel

Music Player DEMO (Randy)

http://www.slideshare.net/randylien/introduce-flux-react-
in-kkbox
@tomchentwhttp://goo.gl/j9M1Nr
對應flux實作
Facebook official flux
@tomchentw
CLIENT SIDE + ROUTING
@tomchentwhttp://goo.gl/j9M1Nr
需要考慮什麼問題
載⼊入⾴頁⾯面相關資料時機

componentDidMount in each “Page” components

伺服器⼀一般設定

必須把可能的路徑都導向該index.html⾴頁⾯面 (catch all route)

可能是 /#! hash based,或使⽤用 HTML5 History API

或採⽤用傳統 SPA 做法,使⽤用404.html === index.html
@tomchentwhttp://goo.gl/j9M1Nr
不需考慮什麼問題
伺服器路由設定

bootstrap initial page, then send ajax requests

Singleton Issue
@tomchentwhttp://goo.gl/j9M1Nr
實際應⽤用例⼦子
Ryan Florence - Hype

http://conf.reactjs.com/schedule.html#hype

Instagram web

https://instagram.com
@tomchentwhttp://goo.gl/j9M1Nr
對應flux實作
Facebook official flux

Fluxxor

react-router
@tomchentw
SERVER SIDE + ROUTING =
ISOMORPHIC
@tomchentwhttp://goo.gl/j9M1Nr
需要考慮什麼問題
載⼊入⾴頁⾯面相關資料時機

分兩種

1. 定義好 routing -> Handler 對應關係,由 Handler
內去拿資料

2. 視 route 改變為⼀一種 flux action,在該action內拿
資料
@tomchentwhttp://goo.gl/j9M1Nr
需要考慮什麼問題(續
伺服器路由設定

考慮⼀一個關鍵問題:什麼時候我才可以吐html回去給客⼾戶
端?

都需要對現有架構做⼀一點改寫

1. 在定義routing時,⼀一起給⼀一個 load function,回
傳 promise

2. 讓 action 可以回傳 promise,代表所需資料載⼊入
完畢
@tomchentwhttp://goo.gl/j9M1Nr
需要考慮什麼問題(續
Singleton Issue

傳統架構 (official flux) 下的 dispatcher/stores 會是
singleton,但node架構會使得所有 request 共享⼀一份

Yahoo 做法:每個 request 皆產⽣生新的 Class instance,⽤用
props 傳⼊入 root component使⽤用

Airbnb 做法:使⽤用 Backbone 的 App instance (also an EE)
@tomchentwhttp://goo.gl/j9M1Nr
實際應⽤用例⼦子
Yahoo Fluxible Samples

Airbnb

https://medium.com/code-stories/dev-chats-spike-brehm-
of-airbnb-87e155f3475d
@tomchentwhttp://goo.gl/j9M1Nr
對應flux實作
Yahoo fluxible

Goflux
@tomchentw
結論
@tomchentwhttp://goo.gl/j9M1Nr
結論
flux 是⼀一種處理資料流的概念

因此允許多種實作

簡單三個分類 flux app

pure client side

client side + routing

server side + routing = isomorphic

以分類來選擇實作
@tomchentw
GOFLUX 簡介
@tomchentw
感謝⼤大家聆聽

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

React.js tw meetup #5