7. ‹#›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
21. ‹#›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) {………………………},
};
22. ‹#›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
23. ‹#›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();
}
});
24. ‹#›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);
}
};
25. ‹#›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”
28. ‹#›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
29. ‹#›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);
}
});