All files reducer.js

100% Statements 8/8
100% Branches 5/5
100% Functions 1/1
100% Lines 8/8
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 30 31 32 33    1x   1x             6x   1x   2x           1x           2x       1x  
import { actionTypes as asyncDataFetchActionTypes } from '@bufferapp/async-data-fetch';
 
export const actionTypes = {};
 
const initialState = {
  metrics: [],
  loading: true,
  hasError: false,
};
 
export default (state = initialState, action) => {
  switch (action.type) {
    case `posts_summary_${asyncDataFetchActionTypes.FETCH_START}`:
      return initialState;
    case `posts_summary_${asyncDataFetchActionTypes.FETCH_SUCCESS}`:
      return {
        ...state,
        loading: false,
        metrics: action.result,
      };
    case `posts_summary_${asyncDataFetchActionTypes.FETCH_FAIL}`:
      return {
        ...initialState,
        loading: false,
        hasError: true,
      };
    default:
      return state;
  }
};
 
export const actions = {};