SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Flux architecture and design
and implementation examples
Iruca3
Aqutras Inc.
What’s Flux?
An architecture of single directional data flow
data-flow programming
or
flow-based programming
https://www.youtube.com/watch?list=PLb0IAmt7-GS188xDYE-u1ShQmFFGbrk0v&v=nYkdrAPrdcw1
Flux provides improvements
- Data consistency
- Easier to pinpoint root of a bug
- More meaningful unit tests
2
Data consistency
Store component manages all of data.
No other components deal with any data.
3
Customer List
Customer Map
Customer Summary
Bad case
Internal DB View Component External DB
Customer
Data
Cached
Customer
Data
Cached
Customer
Data
No consistency
among view components
No consistency
4
Internal DB View Component External DB
Like Flux (not flux but having data consistency)
Customer List
Customer Map
Customer Summary
Store Customer
Data
Web API
Action
ex. CLICK, EDIT, ADD, REMOVE
All changes always come
from some action
Data always come from store
External DB or WebAPI
divided from other components
5
Flux
Store Customer
Data
Web API
Dispatcher handle actions.
Action provides itself to dispatcher.
Dispatcher
Action
View
ex. Customer List, Customer Map, Customer Summary
Which action
does store want?
Which change events
does view want?
Which elements or data
should redraw?
Where do actions
come from?
6
Where do actions come from?
Actions come from View or API.
Web API
View
Action
ex. Update something
ex. Add something
Actions by user interaction
Actions about data changing
7
Implementation sample on Action
createMessage: function(text) {
ChatAppDispatcher.handleViewAction({
type: ActionTypes.CREATE_MESSAGE,
text: text
});
var message = MessageStore.getCreatedMessageData(text);
ChatWebAPIUtils.createMessage(message);
}
Calling WebAPI from Action
https://github.com/facebook/flux/tree/master/examples/flux-chat8
Implementation sample on WebAPI
getAllMessages: function() {
// simulate retrieving data from a database
var rawMessages = JSON.parse(localStorage.getItem('messages'));
// simulate success callback
ChatServerActionCreators.receiveAll(rawMessages);
}
Generating action from WebAPI
https://github.com/facebook/flux/tree/master/examples/flux-chat9
Implementation sample on View
_onKeyDown: function(event) {
if (event.keyCode === ENTER_KEY_CODE) {
var text = this.state.text.trim();
if (text) {
ChatMessageActionCreators.createMessage(text);
}
this.setState({text: ''});
}
}
Generating action from View
https://github.com/facebook/flux/tree/master/examples/flux-chat10
Which action does store wants?
Each store registers itself and provides a callback.
Callback is called with action.
Action
http://facebook.github.io/flux/docs/overview.html#content
Dispatcher Store
Store register itself to Dispatcher with callback below:
function (action) {
if ( action == ‘ADD_CUSTOMER’ ) { /* something */ }
}
Preparing
(Register)
DataFlow
ex.
- ADD_CUSTOMER
- RESIZE
- MOUSEOVER
Store can deal with something
when customer data is changed
11
More complicated case
Dispatcher
Preparing
(Register)
DataFlow
Dispatcher ProductStore
CustomerStore
SalesStore
CustomerStore register
ProductStore register
SalesStore register
ProductStore
CustomerStore
SalesStore
SOLD
Dispatcher should send SOLD
to all storesWeb API
View
Action
Something is brought and
SOLD action emitted
12
Do something
Do something
Do nothing
Implementation sample about
Dispatcher
13
Creating a Dispatcher
http://facebook.github.io/flux/docs/todo-list.html#creating-a-dispatcher
See the document below:
Implementation sample on Store
MessageStore.dispatchToken = ChatAppDispatcher.register(function(payload)
{
var action = payload.action;
switch(action.type) {
case ActionTypes.CLICK_THREAD: (...)
case ActionTypes.CREATE_MESSAGE: (...)
case ActionTypes.RECEIVE_RAW_MESSAGES:
_addMessages(action.rawMessages);
ChatAppDispatcher.waitFor([ThreadStore.dispatchToken]);
_markAllInThreadRead(ThreadStore.getCurrentID());
MessageStore.emitChange();
break;
...
Dealing with specified action
https://github.com/facebook/flux/tree/master/examples/flux-chat14
Registering to dispatcher
Which change events does view want?
View add event listener to Store.
Store has to implement event emitter.
15
Store View
1. addChangeListener(callback)
Store View
3. this.emit(ON_CHANGE)
2. this.on(ON_CHANGE, callback)
ON_CHANGE is a simple constant string
4. Callback is called
Implementation sample on View
componentDidMount: function() {
this._scrollToBottom();
MessageStore.addChangeListener(this._onChange);
ThreadStore.addChangeListener(this._onChange);
}
Registering store change listener
https://github.com/facebook/flux/tree/master/examples/flux-chat16
Implementation sample on Store
emitChange: function() {
this.emit(CHANGE_EVENT);
},
addChangeListener: function(callback) {
this.on(CHANGE_EVENT, callback);
}
Registering store change listener
https://github.com/facebook/flux/tree/master/examples/flux-chat17
Event should be fired
on ONLY dispatching
because data flow shows that
input is only Dispatcher.
Which elements or data should redraw?
React does very well
if you use props and state correctly.
See the document below:
15
Advanced Performance
http://facebook.github.io/react/docs/advanced-performance.html
Reconciliation
http://facebook.github.io/react/docs/reconciliation.html
Flux flow loop
15
Store
Server DBWeb API
Dispatcher
Action
View
Store registers itself
to dispatcher.
View adds event listener
to store.
View creates an action.
Action notify to dispatcher.
Dispatcher handle actions.
Action calls some web api.
Web api creates an action.

Weitere ähnliche Inhalte

Ähnlich wie Flux memo

Academy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingAcademy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingBinary Studio
 
Hazelcast Striim Hot Cache Presentation
Hazelcast Striim Hot Cache PresentationHazelcast Striim Hot Cache Presentation
Hazelcast Striim Hot Cache PresentationSteve Wilkes
 
SQL Server 2008 Portfolio for Saumya Bhatnagar
SQL Server 2008 Portfolio for Saumya BhatnagarSQL Server 2008 Portfolio for Saumya Bhatnagar
SQL Server 2008 Portfolio for Saumya Bhatnagarsammykb
 
Getting started with Redux js
Getting started with Redux jsGetting started with Redux js
Getting started with Redux jsCitrix
 
[@NaukriEngineering] Flux Architecture
[@NaukriEngineering] Flux Architecture[@NaukriEngineering] Flux Architecture
[@NaukriEngineering] Flux ArchitectureNaukri.com
 
Applications: A Series of States
Applications: A Series of StatesApplications: A Series of States
Applications: A Series of StatesTrek Glowacki
 
Building a Backend with Flask
Building a Backend with FlaskBuilding a Backend with Flask
Building a Backend with FlaskMake School
 
Azure Data Factory Introduction.pdf
Azure Data Factory Introduction.pdfAzure Data Factory Introduction.pdf
Azure Data Factory Introduction.pdfMaheshPandit16
 
Battle of React State Managers in frontend applications
Battle of React State Managers in frontend applicationsBattle of React State Managers in frontend applications
Battle of React State Managers in frontend applicationsEvangelia Mitsopoulou
 
Database Change Management as a Service
Database Change Management as a ServiceDatabase Change Management as a Service
Database Change Management as a ServiceAndrew Solomon
 
Skills Portfolio
Skills PortfolioSkills Portfolio
Skills Portfoliorolee23
 
BP204 - Take a REST and put your data to work with APIs!
BP204 - Take a REST and put your data to work with APIs!BP204 - Take a REST and put your data to work with APIs!
BP204 - Take a REST and put your data to work with APIs!Craig Schumann
 
Java Web Programming [8/9] : JSF and AJAX
Java Web Programming [8/9] : JSF and AJAXJava Web Programming [8/9] : JSF and AJAX
Java Web Programming [8/9] : JSF and AJAXIMC Institute
 
Server side rendering with React and Symfony
Server side rendering with React and SymfonyServer side rendering with React and Symfony
Server side rendering with React and SymfonyIgnacio Martín
 
Code First with Serverless Azure Functions
Code First with Serverless Azure FunctionsCode First with Serverless Azure Functions
Code First with Serverless Azure FunctionsJeremy Likness
 
Going Serverless with Azure Functions in .NET
Going Serverless with Azure Functions in .NETGoing Serverless with Azure Functions in .NET
Going Serverless with Azure Functions in .NETJeremy Likness
 

Ähnlich wie Flux memo (20)

Academy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingAcademy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & Tooling
 
Hazelcast Striim Hot Cache Presentation
Hazelcast Striim Hot Cache PresentationHazelcast Striim Hot Cache Presentation
Hazelcast Striim Hot Cache Presentation
 
SQL Server 2008 Portfolio for Saumya Bhatnagar
SQL Server 2008 Portfolio for Saumya BhatnagarSQL Server 2008 Portfolio for Saumya Bhatnagar
SQL Server 2008 Portfolio for Saumya Bhatnagar
 
Getting started with Redux js
Getting started with Redux jsGetting started with Redux js
Getting started with Redux js
 
[@NaukriEngineering] Flux Architecture
[@NaukriEngineering] Flux Architecture[@NaukriEngineering] Flux Architecture
[@NaukriEngineering] Flux Architecture
 
Applications: A Series of States
Applications: A Series of StatesApplications: A Series of States
Applications: A Series of States
 
Sql Portfolio
Sql PortfolioSql Portfolio
Sql Portfolio
 
Building a Backend with Flask
Building a Backend with FlaskBuilding a Backend with Flask
Building a Backend with Flask
 
Using Embulk at Treasure Data
Using Embulk at Treasure DataUsing Embulk at Treasure Data
Using Embulk at Treasure Data
 
Asp.net tips
Asp.net tipsAsp.net tips
Asp.net tips
 
Introduction to BreezeJs
Introduction to BreezeJsIntroduction to BreezeJs
Introduction to BreezeJs
 
Azure Data Factory Introduction.pdf
Azure Data Factory Introduction.pdfAzure Data Factory Introduction.pdf
Azure Data Factory Introduction.pdf
 
Battle of React State Managers in frontend applications
Battle of React State Managers in frontend applicationsBattle of React State Managers in frontend applications
Battle of React State Managers in frontend applications
 
Database Change Management as a Service
Database Change Management as a ServiceDatabase Change Management as a Service
Database Change Management as a Service
 
Skills Portfolio
Skills PortfolioSkills Portfolio
Skills Portfolio
 
BP204 - Take a REST and put your data to work with APIs!
BP204 - Take a REST and put your data to work with APIs!BP204 - Take a REST and put your data to work with APIs!
BP204 - Take a REST and put your data to work with APIs!
 
Java Web Programming [8/9] : JSF and AJAX
Java Web Programming [8/9] : JSF and AJAXJava Web Programming [8/9] : JSF and AJAX
Java Web Programming [8/9] : JSF and AJAX
 
Server side rendering with React and Symfony
Server side rendering with React and SymfonyServer side rendering with React and Symfony
Server side rendering with React and Symfony
 
Code First with Serverless Azure Functions
Code First with Serverless Azure FunctionsCode First with Serverless Azure Functions
Code First with Serverless Azure Functions
 
Going Serverless with Azure Functions in .NET
Going Serverless with Azure Functions in .NETGoing Serverless with Azure Functions in .NET
Going Serverless with Azure Functions in .NET
 

Kürzlich hochgeladen

2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projectssmsksolar
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...soginsider
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptMsecMca
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf203318pmpc
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoordharasingh5698
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfRagavanV2
 

Kürzlich hochgeladen (20)

2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
 

Flux memo

  • 1. Flux architecture and design and implementation examples Iruca3 Aqutras Inc.
  • 2. What’s Flux? An architecture of single directional data flow data-flow programming or flow-based programming https://www.youtube.com/watch?list=PLb0IAmt7-GS188xDYE-u1ShQmFFGbrk0v&v=nYkdrAPrdcw1
  • 3. Flux provides improvements - Data consistency - Easier to pinpoint root of a bug - More meaningful unit tests 2
  • 4. Data consistency Store component manages all of data. No other components deal with any data. 3
  • 5. Customer List Customer Map Customer Summary Bad case Internal DB View Component External DB Customer Data Cached Customer Data Cached Customer Data No consistency among view components No consistency 4
  • 6. Internal DB View Component External DB Like Flux (not flux but having data consistency) Customer List Customer Map Customer Summary Store Customer Data Web API Action ex. CLICK, EDIT, ADD, REMOVE All changes always come from some action Data always come from store External DB or WebAPI divided from other components 5
  • 7. Flux Store Customer Data Web API Dispatcher handle actions. Action provides itself to dispatcher. Dispatcher Action View ex. Customer List, Customer Map, Customer Summary Which action does store want? Which change events does view want? Which elements or data should redraw? Where do actions come from? 6
  • 8. Where do actions come from? Actions come from View or API. Web API View Action ex. Update something ex. Add something Actions by user interaction Actions about data changing 7
  • 9. Implementation sample on Action createMessage: function(text) { ChatAppDispatcher.handleViewAction({ type: ActionTypes.CREATE_MESSAGE, text: text }); var message = MessageStore.getCreatedMessageData(text); ChatWebAPIUtils.createMessage(message); } Calling WebAPI from Action https://github.com/facebook/flux/tree/master/examples/flux-chat8
  • 10. Implementation sample on WebAPI getAllMessages: function() { // simulate retrieving data from a database var rawMessages = JSON.parse(localStorage.getItem('messages')); // simulate success callback ChatServerActionCreators.receiveAll(rawMessages); } Generating action from WebAPI https://github.com/facebook/flux/tree/master/examples/flux-chat9
  • 11. Implementation sample on View _onKeyDown: function(event) { if (event.keyCode === ENTER_KEY_CODE) { var text = this.state.text.trim(); if (text) { ChatMessageActionCreators.createMessage(text); } this.setState({text: ''}); } } Generating action from View https://github.com/facebook/flux/tree/master/examples/flux-chat10
  • 12. Which action does store wants? Each store registers itself and provides a callback. Callback is called with action. Action http://facebook.github.io/flux/docs/overview.html#content Dispatcher Store Store register itself to Dispatcher with callback below: function (action) { if ( action == ‘ADD_CUSTOMER’ ) { /* something */ } } Preparing (Register) DataFlow ex. - ADD_CUSTOMER - RESIZE - MOUSEOVER Store can deal with something when customer data is changed 11
  • 13. More complicated case Dispatcher Preparing (Register) DataFlow Dispatcher ProductStore CustomerStore SalesStore CustomerStore register ProductStore register SalesStore register ProductStore CustomerStore SalesStore SOLD Dispatcher should send SOLD to all storesWeb API View Action Something is brought and SOLD action emitted 12 Do something Do something Do nothing
  • 14. Implementation sample about Dispatcher 13 Creating a Dispatcher http://facebook.github.io/flux/docs/todo-list.html#creating-a-dispatcher See the document below:
  • 15. Implementation sample on Store MessageStore.dispatchToken = ChatAppDispatcher.register(function(payload) { var action = payload.action; switch(action.type) { case ActionTypes.CLICK_THREAD: (...) case ActionTypes.CREATE_MESSAGE: (...) case ActionTypes.RECEIVE_RAW_MESSAGES: _addMessages(action.rawMessages); ChatAppDispatcher.waitFor([ThreadStore.dispatchToken]); _markAllInThreadRead(ThreadStore.getCurrentID()); MessageStore.emitChange(); break; ... Dealing with specified action https://github.com/facebook/flux/tree/master/examples/flux-chat14 Registering to dispatcher
  • 16. Which change events does view want? View add event listener to Store. Store has to implement event emitter. 15 Store View 1. addChangeListener(callback) Store View 3. this.emit(ON_CHANGE) 2. this.on(ON_CHANGE, callback) ON_CHANGE is a simple constant string 4. Callback is called
  • 17. Implementation sample on View componentDidMount: function() { this._scrollToBottom(); MessageStore.addChangeListener(this._onChange); ThreadStore.addChangeListener(this._onChange); } Registering store change listener https://github.com/facebook/flux/tree/master/examples/flux-chat16
  • 18. Implementation sample on Store emitChange: function() { this.emit(CHANGE_EVENT); }, addChangeListener: function(callback) { this.on(CHANGE_EVENT, callback); } Registering store change listener https://github.com/facebook/flux/tree/master/examples/flux-chat17 Event should be fired on ONLY dispatching because data flow shows that input is only Dispatcher.
  • 19. Which elements or data should redraw? React does very well if you use props and state correctly. See the document below: 15 Advanced Performance http://facebook.github.io/react/docs/advanced-performance.html Reconciliation http://facebook.github.io/react/docs/reconciliation.html
  • 20. Flux flow loop 15 Store Server DBWeb API Dispatcher Action View Store registers itself to dispatcher. View adds event listener to store. View creates an action. Action notify to dispatcher. Dispatcher handle actions. Action calls some web api. Web api creates an action.