SlideShare a Scribd company logo
Flux – Rethink In Design Pattern
JULY, 2015
‹#›CONFIDENTIAL
AGENDA
•What is wrong with MVC?
•Flux in a nutshell
•React as a part of Flux
•What is wrong with Flux?
•Flux frameworks overview
‹#›CONFIDENTIAL
WHAT IS WRONG WITH MVC?
‹#›CONFIDENTIAL
COMMON MVC DIAGRAM
‹#›CONFIDENTIAL
IDEAL MVC APPLICATION
‹#›CONFIDENTIAL
REAL MVC APPLICATION
‹#›CONFIDENTIAL
Models can send events to many views as well as
views too
1
Common two-way binding pattern leads to cascade
changes, which hard to debug
2
No single entry point for actions, so any function can
be publisher or subscriber of event
3
Single responsibility principle is usually become
broken
4
MAIN ISSUES
‹#›CONFIDENTIAL
FLUX IN A NUTSHELL
‹#›CONFIDENTIAL
FLUX COMMON DIAGRAM
(c) http://facebook.github.io/flux/docs/overview.html
‹#›CONFIDENTIAL
DISPATHER
class Dispatcher {
register(callback) {}
unregister(id) {}
waitFor(ids) {}
dispatch(payload) {
for (var id in this._callbacks) {
this._invokeCallback(id);
}
}
_invokeCallback(id) {}
}
‹#›CONFIDENTIAL
STORE
class Store = {
emitChange: function(CHANGE_EVENT) {},
addChangeListener: function(CHANGE_EVENT , callback) {},
removeChangeListener: function(CHANGE_EVENT , callback) {}
};
Dispatcher.register(function(action) {
switch(action.actionType) {
case ACTIONS.ACTION1:
// do something
Store.emitChange(CHANGE_EVENT1);
case ACTIONS.ACTION2:
// do something
Store.emitChange(CHANGE_EVENT2);
}
});
‹#›CONFIDENTIAL
ACTIONS
class Actions = {
action1Function: function(params) {
Dispatcher.dispatch({
actionType: ACTION1,
params: params
});
},
action2Function: function(params) {
Dispatcher.dispatch({
actionType: ACTION2,
params: params
});
}
};
‹#›CONFIDENTIAL
VIEW
class View = {
onEvent1: function() {
Actions.action1Function(params);
},
onEvent2: function() {
Actions.action2Function(params);
}
};
‹#›CONFIDENTIAL
REACT AS A PART OF FLUX
‹#›CONFIDENTIAL
FLUX + REACT WEB DIAGRAM
(c) https://github.com/facebook/flux
‹#›CONFIDENTIAL
Decoupling with component model1
Virtual DOM, synthetic events and fast render2
No templates, code and markup in one place3
Uni-directional flow4
‹#›CONFIDENTIAL
REACT BACKBONE
‹#›CONFIDENTIAL
VIRTUAL DOM VS REAL DOM
‹#›CONFIDENTIAL
React View Life Cycle
‹#›CONFIDENTIAL
WHAT IS WRONG WITH FLUX?
‹#›CONFIDENTIAL
ACTIONS list and file grows with complexity of
application
1
class Actions = {
action1Function: function(params) {………………………},
action2Function: function(params) {………………………},
action3Function: function(params) {………………………},
action4Function: function(params) {………………………},
action5Function: function(params) {………………………},
action6Function: function(params) {………………………},
action7Function: function(params) {………………………},
};
‹#›CONFIDENTIAL
When to create new STORE, what are criteria of
STORE as definite entity?
2
Facebook: “Stores are not models, not single records, not collectio
‹#›CONFIDENTIAL
Can STORE produce ACTION? Does it break the flow?3
class Store = {
doSomething: function() {
Actions.action1Function(params);
}
};
Dispatcher.register(function(action) {
switch(action.actionType) {
case ACTIONS.ACTION1:
Store.doSomething();
}
});
‹#›CONFIDENTIAL
Is it eligible to call two ACTIONS in a row? Does it
break the flow?
4
class View = {
onEvent1: function() {
Actions.action1Function(params);
Actions.action2Function(params);
}
};
‹#›CONFIDENTIAL
Is FLUX framework or pattern?5
Facebook: “Flux is the application architecture that Facebook
uses for building client-side web applications. It complements
React's composable view components by utilizing a
unidirectional data flow. It's more of a pattern rather than a
formal framework”
‹#›CONFIDENTIAL
FLUX FRAMEWORKS OVERVIEW
‹#›CONFIDENTIAL
REFLUX JS
‹#›CONFIDENTIAL
REFLUX JS
(c) https://github.com/spoike/refluxjs
The singleton dispatcher is removed in favor for
letting every action act as dispatcher instead
1
Because actions are listenable, the stores may listen
to them. Stores don't need to have big switch
statements that do static type checking with strings
2
Stores may listen to other stores, i.e. it is possible to
create stores that can aggregate data further,
similar to a map/reduce
3
waitFor is replaced in favor to handle serial and
parallel data flows
4
Action creators are not needed because RefluxJS
actions are functions that will pass on the payload
they receive to anyone listening to them
5
‹#›CONFIDENTIAL
var Actions = Reflux.createActions({
"loadData": {children: ["completedData","failedData"]}
});
Actions.loadData.listen( function() {
ajaxAsyncOperation()
.then( this.completedData )
.catch( this.failedData);
});
var Store = Reflux.createStore({
init: function() {
this.listenToMany(Actions);
},
onCompletedData: function(){},
onFailedData: function(){}
});
var Store = Reflux.createStore({
init: function() {
this.joinLeading(actions.action1,
actions.action2, actions.action3);
}
});
‹#›CONFIDENTIAL
DELOREAN JS
‹#›CONFIDENTIAL
DELOREAN JS
Unidirectional data flow1
Automatically listens to data changes and keeps data
updated
2
Makes data more consistent across whole application3
‹#›CONFIDENTIAL
var Store = DeLorean.Flux.createStore({
setData: function (data) {
this.data = data;
this.emit('change');
},
actions: { 'incoming-data': ‘setData' }
});
var Dispatcher = DeLorean.Flux.createDispatcher({
setData: function (data) {
this.dispatch('incoming-data', data);
},
getStores: function () { return {increment: Store}; }
});
var Actions = {
setData: function (data) {
Dispatcher.setData(data);
}
};
Store.onChange(function () {
document.getElementById('result').innerText = store.data;
});
document.getElementById('dataChanger').onclick = function () {
Actions.setData(Math.random());
};
‹#›CONFIDENTIAL
FLUXXOR
‹#›CONFIDENTIAL
FLUXXOR
Easy to bind actions1
Dispatch function is moved to actions layer2
Built-in integration with React components3
‹#›CONFIDENTIAL
var Store = Fluxxor.createStore({
initialize: function() {
this.bindActions(ACTION1, this.onAction1);
},
onAction1: function(payload) {
//do something
this.emit("change");
}
});
var actions = {
action1: function(payload) {
this.dispatch(ACTION1, payload);
}
};
var FluxMixin = Fluxxor.FluxMixin(React), StoreWatchMixin =
Fluxxor.StoreWatchMixin;
var Application = React.createClass({
mixins: [FluxMixin, StoreWatchMixin("Store")],
getStateFromFlux: function() {
return this.getFlux().store("Store").getState();
},
render: function () {}
});
‹#›CONFIDENTIAL
REFERENCE
https://github.com/facebook/flux
http://facebook.github.io/react/blog/2014/05/06/flux.html
https://facebook.github.io/react/docs/component-specs.html
https://github.com/voronianski/flux-comparison
https://www.youtube.com/watch?v=LTj4O7WJJ98
‹#›CONFIDENTIAL
THANKQ
Q&A

More Related Content

PPT
Building Reactive webapp with React/Flux
PPTX
Discuss About ASP.NET MVC 6 and ASP.NET MVC 5
PDF
Introduce flux & react in practice
PPTX
Tarabica 2019 - Migration from ASP.NET MVC to ASP.NET Core
PPTX
Introduction to ASP.NET MVC
PPTX
Angular on ASP.NET MVC 6
PDF
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
PDF
MidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
Building Reactive webapp with React/Flux
Discuss About ASP.NET MVC 6 and ASP.NET MVC 5
Introduce flux & react in practice
Tarabica 2019 - Migration from ASP.NET MVC to ASP.NET Core
Introduction to ASP.NET MVC
Angular on ASP.NET MVC 6
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
MidwestJS 2014 Reconciling ReactJS as a View Layer Replacement

What's hot (20)

PPTX
Reactive Web Development with Spring Boot 2
PPTX
Backbonemeetup
PDF
The Dark Side of Single Page Applications
PPTX
Micro-frontends – is it a new normal?
PPTX
Webinar MVC6
PPTX
Introducing ASP.NET Core 2.0
PPTX
Testing your Single Page Application
PPTX
Extensibility for ADF applications
PDF
Real World Windows Phone Development
PDF
Laravel 5.4
PPTX
Solving micro-services and one site problem
PPTX
Asp.net Overview and Controllers
PPTX
ASP.NET MVC, AngularJS CRUD for Azerbaijan Technical University
PPTX
Grails Spring Boot
PDF
Learning Rails
PDF
Let's set the record straight on the term serverless and what it’s not
PPTX
Single Page Application JS Framework Round up
PDF
Tomasz Janczuk - Webtaskalifragilistexpialidocious
PDF
Tech Talk on ReactJS
PDF
React.js - and how it changed our thinking about UI
Reactive Web Development with Spring Boot 2
Backbonemeetup
The Dark Side of Single Page Applications
Micro-frontends – is it a new normal?
Webinar MVC6
Introducing ASP.NET Core 2.0
Testing your Single Page Application
Extensibility for ADF applications
Real World Windows Phone Development
Laravel 5.4
Solving micro-services and one site problem
Asp.net Overview and Controllers
ASP.NET MVC, AngularJS CRUD for Azerbaijan Technical University
Grails Spring Boot
Learning Rails
Let's set the record straight on the term serverless and what it’s not
Single Page Application JS Framework Round up
Tomasz Janczuk - Webtaskalifragilistexpialidocious
Tech Talk on ReactJS
React.js - and how it changed our thinking about UI
Ad

Similar to Flux - rethink in design pattern (20)

PPT
PPTX
Intro to Flux - ReactJS Warsaw #1
PPTX
React. Flux. Redux. by Andrey Kolodnitskiy
PPTX
Flux memo
PDF
Flux architecture and Redux - theory, context and practice
PPTX
What is flux architecture in react
PPTX
React. Flux. Redux
PPTX
Flux and React.js
ODP
Fluxxor react library
PDF
Instant download Flux Architecture 1 edition Edition Boduch pdf all chapter
PDF
Flux Architecture 1 edition Edition Boduch
PDF
Flux Architecture 1 edition Edition Boduch
PDF
About Flux
PDF
Flux on i os
PDF
[@NaukriEngineering] Flux Architecture
PDF
From Back to Front: Rails To React Family
PPTX
Flux architecture
PDF
Manage the Flux of your Web Application: Let's Redux
PDF
An Intense Overview of the React Ecosystem
Intro to Flux - ReactJS Warsaw #1
React. Flux. Redux. by Andrey Kolodnitskiy
Flux memo
Flux architecture and Redux - theory, context and practice
What is flux architecture in react
React. Flux. Redux
Flux and React.js
Fluxxor react library
Instant download Flux Architecture 1 edition Edition Boduch pdf all chapter
Flux Architecture 1 edition Edition Boduch
Flux Architecture 1 edition Edition Boduch
About Flux
Flux on i os
[@NaukriEngineering] Flux Architecture
From Back to Front: Rails To React Family
Flux architecture
Manage the Flux of your Web Application: Let's Redux
An Intense Overview of the React Ecosystem
Ad

Recently uploaded (20)

PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
Lecture Notes Electrical Wiring System Components
PDF
composite construction of structures.pdf
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
Welding lecture in detail for understanding
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Operating System & Kernel Study Guide-1 - converted.pdf
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
CYBER-CRIMES AND SECURITY A guide to understanding
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Foundation to blockchain - A guide to Blockchain Tech
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Lecture Notes Electrical Wiring System Components
composite construction of structures.pdf
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Embodied AI: Ushering in the Next Era of Intelligent Systems
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Welding lecture in detail for understanding
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx

Flux - rethink in design pattern