holds the data of our application
~ Tony
export interface State {
todos: string[];
}
unique method that tells the dispatcher what to do to the state
~ Tony
const addTodoAction = {
type: 'ADD_TODO',
payload: string
};
const completeTodoAction = {
type: 'COMPLETE_TODO',
payload: string
};
calls methods registered by the store
~ Tony
todoDispatcher.register(function(payload) {
if (payload.type === 'ADD_TODO') {
store.todos.add(payload);
}
});
todoDispatcher.dispatch({
action: 'ADD_TODO',
payload: 'Call Mom'
});
Andrew Clark
Dan Abramov
Flux
Redux
NGRX
NGRX
Flux
Redux
single store
one source of truth
no dispatcher
immutable state
multiple source of truth
singleton dispatcher
mutable state
multiple store
store
store
VS
~ Dave Ceddia
var letters = ['r', 'e', 'd', 'u', 'x'];
var word = letters.reduce(
function(accumulatedResult, arrayItem) {
return accumulatedResult + arrayItem;
},
'');
console.log(word) // => "redux"
function wordReducer(state, action) {
switch(action.type) {
case 'ADD_LETTER':
return state + action.letter;
default:
return state;
}
}
click
event
add
todo
current
state
new
state
todos: {'Call Mom'}
npm install @ngrx/store
@ngrx/store-devtools --save
click
event
"You should use ngrx"
you
your boss
using ngrx
when you haven't told someone about ngrx in 5 minutes
you not using ngrx
me