2018-02-28 15:45:16 -05:00
|
|
|
import { Map } from 'immutable';
|
|
|
|
import { CONFIG_REQUEST, CONFIG_SUCCESS, CONFIG_FAILURE, CONFIG_MERGE } from 'Actions/config';
|
2016-02-25 00:45:56 -08:00
|
|
|
|
2018-02-28 15:45:16 -05:00
|
|
|
const config = (state = Map({ isFetching: true }), action) => {
|
2016-02-25 00:45:56 -08:00
|
|
|
switch (action.type) {
|
2018-02-28 15:45:16 -05:00
|
|
|
case CONFIG_MERGE:
|
|
|
|
return state.mergeDeep(action.payload);
|
2016-02-25 12:31:21 -08:00
|
|
|
case CONFIG_REQUEST:
|
2018-02-28 15:45:16 -05:00
|
|
|
return state.set('isFetching', true);
|
2016-02-25 12:31:21 -08:00
|
|
|
case CONFIG_SUCCESS:
|
2018-02-28 15:45:16 -05:00
|
|
|
/**
|
|
|
|
* The loadConfig action merges any existing config into the loaded config
|
|
|
|
* before firing this action (so the resulting config can be validated),
|
|
|
|
* so we don't have to merge it here.
|
|
|
|
*/
|
|
|
|
return action.payload.delete('isFetching');
|
2016-02-25 12:31:21 -08:00
|
|
|
case CONFIG_FAILURE:
|
2018-02-28 15:45:16 -05:00
|
|
|
return Map({ error: action.payload.toString() });
|
2016-02-25 00:45:56 -08:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
2016-06-10 00:16:01 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
export default config;
|