25 lines
800 B
JavaScript
Raw Normal View History

import { Map } from 'immutable';
import { CONFIG_REQUEST, CONFIG_SUCCESS, CONFIG_FAILURE, CONFIG_MERGE } from 'Actions/config';
2016-02-25 00:45:56 -08:00
const config = (state = Map({ isFetching: true }), action) => {
2016-02-25 00:45:56 -08:00
switch (action.type) {
case CONFIG_MERGE:
return state.mergeDeep(action.payload);
case CONFIG_REQUEST:
return state.set('isFetching', true);
case CONFIG_SUCCESS:
/**
* 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');
case CONFIG_FAILURE:
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;