All files / answers-chart reducer.js

83.33% Statements 5/6
80% Branches 4/5
100% Functions 1/1
83.33% Lines 5/6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29    2x             4x       2x           1x           1x      
import { actionTypes as asyncDataFetchActionTypes } from '@bufferapp/async-data-fetch';
 
const initialState = {
  loading: true,
  hasError: false,
  answers: null,
};
 
export default (state = initialState, action) => {
  switch (action.type) {
    case `answers_${asyncDataFetchActionTypes.FETCH_START}`:
      return initialState;
    case `answers_${asyncDataFetchActionTypes.FETCH_SUCCESS}`:
      return {
        ...state,
        loading: false,
        answers: action.result,
      };
    case `answers_${asyncDataFetchActionTypes.FETCH_FAIL}`:
      return {
        ...initialState,
        loading: false,
        hasError: true,
      };
    default:
      return state;
  }
};