All files / src/containers/ApiCalls reducer.js

92.86% Statements 13/14
81.82% Branches 9/11
100% Functions 1/1
92.86% Lines 13/14
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        5x 1x     4x 1x     3x 3x 1x 1x     2x 1x     1x 1x     1x          
import { Map } from 'immutable';
import ApiCall from './';
 
export default function apiCalls(state = Map(), action) {
  if (action.type === ApiCall.API_CALL_CLEAN) {
    return state.remove(action.key);
  }
 
  if (! ApiCall.Action.isApiAction(action)) {
    return state;
  }
 
  const key = ApiCall.Key.create(action);
  if (ApiCall.Action.isStarted(action)) {
    const newState = ApiCall.State.createLoading(key, { disableDefault: action.disableDefault });
    return state.set(key, newState);
  }
 
  if (ApiCall.Action.isSuccess(action)) {
    return state.set(key, ApiCall.State.createSucceeded(key));
  }
 
  Eif (ApiCall.Action.isFailure(action)) {
    const newState = ApiCall.State.createFailed(key,
        action.error,
        { disableDefault: action.disableDefault });
    return state.set(key, newState);
  }
 
  return state;
}