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;
}
}
|