38 lines
798 B
JavaScript
Raw Normal View History

2017-01-17 13:40:59 +01:00
/*
* Reducer
*
* The reducer takes care of our data. Using actions, we can change our
* application state.
* To add a new action, add it to the switch statement in the reducer function
*
* Example:
* case YOUR_ACTION_CONSTANT:
* return state.set('yourStateVariable', true);
*/
import { fromJS } from 'immutable';
2017-01-19 16:42:16 +01:00
import { LOAD, LOAD_SUCCESS } from './constants';
2017-01-17 13:40:59 +01:00
// The initial state of the App
const initialState = fromJS({
2017-01-19 16:42:16 +01:00
loading: false,
name: null
2017-01-17 13:40:59 +01:00
});
function appReducer(state = initialState, action) {
switch (action.type) {
2017-01-19 16:42:16 +01:00
case LOAD:
return state
.set('loading', true);
case LOAD_SUCCESS:
2017-01-17 13:40:59 +01:00
return state
2017-01-19 16:42:16 +01:00
.set('name', action.data.name)
.set('loading', false);
2017-01-17 13:40:59 +01:00
default:
return state;
}
}
export default appReducer;