//entire application state
{
isLoading: false,
toDos: [
{
title: 'Prepare Slide',
action: 'try to be funny',
comment: 'fail miserably'
},
{
title: 'Cant think of anything',
action: 'something something',
comment: 'something something'
}
]
}
Only way to change the state is to dispatch action
store.dispatch({
type: 'ADD_TODO',
data: {
title: 'Hi',
action: 'Umm',
comment: 'Bye'
}
})
just a function that returns a new state
toDoReducer = (state = [], action) => {
switch(action.type) {
case ADD_TODO:
//returns newState;
default:
return state;
}
}toDoReducer = (state = [], action) => {
switch(action.type) {
case ADD_TODO:
return state.push(action.data);
default:
return state;
}
}toDoReducer = (state = [], action) => {
switch(action.type) {
case ADD_TODO:
return [...state, Object.assign({}, action.data)];
default:
return state;
}
}React : Someone just clicked the save button.
Action : I will tell the reducers.
Reducer : I will change the state.
Store : I'll notify all the components.
React : Updating the UI!