not specifically Facebook's Flux implementation
throughout this presentation...
https://facebook.github.io/flux/docs/overview.html
http://fluxxor.com/what-is-flux.html
abnormally simple MVC
model
view
controller
action
https://facebook.github.io/flux/docs/overview.html
http://fluxxor.com/what-is-flux.html
abnormally simple MVC
model
view
controller
action
view
view
https://facebook.github.io/flux/docs/overview.html
http://fluxxor.com/what-is-flux.html
abnormally simple MVC
model
view
controller
action
view
view
model
https://facebook.github.io/flux/docs/overview.html
http://fluxxor.com/what-is-flux.html
still a pretty simple MV*
model
view
model
view
model
view
model
view
model
view
model
view
model
view
controller
controller
https://facebook.github.io/flux/docs/overview.html
http://fluxxor.com/what-is-flux.html
still a pretty simple MV*
model
view
model
view
model
view
model
view
model
view
model
view
model
view
controller
controller
still problematic at scale
model
view
model
view
model
view
model
view
model
view
model
view
model
view
to fully understand this
<---------
{
you must understand all this
and know all the places where state can be mutated
}
and maybe this
and potentially how
controller
and maybe this
Banana vs Jungle
maybe these
view
model
{}
</>
store
view
store
{}
</>
smart component
</>
</>
</>
dumb components
view
all completely reactive to store
export default ({ people }) => {
let list = people.map( person => (
<li>
<strong>{ person.name }</strong>
: <small>{ person.about }</small>
</li>
));
return people.length
? <ul>{ list }</ul>
: <strong>No Peeps</strong>;
};
https://jsbin.com/qeguge/edit?js,output
{}
</>
</>
</>
</>
How do I change the rendered UI of this component?
Change the state in the store.
{}
model / state
notifier
action handler(s)
listener
regarding the store: as an app dev, you only write action handlers
{}
{
"type": "ADD_PERSON",
"name": "Jared",
"location": "South Jordan, UT",
"food": ["pizza", "bacon"]
}
to understand action handlers, let's talk...
{
"type": "INCREMENT_COUNTER"
}
function myCounter(state=0, action) {
switch(action.type) {
case "INCREMENT_COUNTER":
return state+1;
case "DECREMENT_COUNTER":
return state-1;
default:
return state;
}
}
import { createStore } from 'redux'
function todos(state = [], action) {
switch (action.type) {
case 'ADD_TODO':
return state.concat({
task: action.item,
id: state.length+1
});
case 'REMOVE_TODO':
return state.filter(item=>item.id!==action.id);
default:
return state
}
}
let store = createStore(todos);
store.subscribe( () => console.log(
store.getState()
));
https://jsbin.com/quyotan/edit?js,console
{}
</>
</>
</>
</>
export function addTodo(text) {
return {
type: ADD_TODO,
text
};
}
http://rackt.org/redux/docs/basics/Actions.html
import { dispatch } from './store.js';
import { addTodo } from './actions/add-todo.js';
import { Dumb } from './components/dumb.js';
// to be passed into dumb component(s)
let add = text => (
dispatch( addTodo(text) )
);
// later usage:
<Dumb addAction={add} />
../actions/add-todo.js
./some/smart-component.js
{}
</>
</>
</>
</>
who believes they:
{}
</>
</>
</>
</>
Of this system, these are the things you write
{}
</>
</>
</>
</>
Action Handlers & Dumb Components
{}
</>
</>
</>
</>
Action Creator
thus, requires some awareness of the system
{}
</>
</>
</>
</>
Smart Component / Controller-View
each unit is:
FTW
{}
</>
</>
</>
</>
start with
{}
</>
</>
</>
</>
</>
</>
</>
</>
</>
</>
no effect on system complexity
{}
</>
</>
</>
</>
</>
</>
</>
</>
</>
</>
</>
</>
no effect on system complexity
{}
</>
</>
</>
</>
</>
</>
</>
</>
</>
</>
may result in more action creators
but no increase in system complexity
</>
</>
Other Visual Representations
per Google Image search ;)
action
view
store
dispatch
action creator
smart component
store
dispatch
dumb component
api
user
interaction
https://jsbin.com/sagafug/edit?js,output