All files / reducers EventReducer.js

0% Statements 0/25
0% Branches 0/15
0% Functions 0/4
0% Lines 0/9
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47                                                                                             
import { request, invalidate, initState } from '../boilerplate';
import { REQUEST_EVENTS, RECEIVE_EVENTS, INVALIDATE_EVENTS, CHANGE_READ_STATUS } from '../actionTypes';
 
/* Not too sure what to do with events. */
function receive(state, action) {
  const nextState = {
    data: action.response,
    isFetching: false,
    didInvalidate: false,
    lastAction: {
      type: action.type,
      status: action.status,
    },
  };
  return { ...state, ...nextState };
}
 
function changeReadStatus(state, action) {
  const nextState = {
    lastAction: {
      type: action.type,
      status: action.status,
    },
  };
 
  if (action.status === 'error') {
    nextState.lastAction.error = action.error;
  }
 
  return { ...state, ...nextState };
}
 
export default function(state = initState, action) {
  switch (action.type) {
    case REQUEST_EVENTS:
      return request(state, action);
    case RECEIVE_EVENTS:
      return receive(state, action);
    case INVALIDATE_EVENTS:
      return invalidate(state, action);
    case CHANGE_READ_STATUS:
      return changeReadStatus(state, action);
    default:
      return state;
  }
}