All files / src/app/store/reducers ui.reducer.ts

100% Statements 12/12
80% Branches 8/10
100% Functions 2/2
100% Lines 11/11
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       7x 7x     2x 2x     2x 2x         1x 1x     2x       5x        
import { Action, Reducer } from 'redux';
 
const initialState = {
  activeRequests: 0
};
 
export const uiReducer: Reducer<any> = (Istate: any = initialState, action: any) => {
  switch (action.type) {
 
    case '[UI] INCREMENT_LOADING':
      action.type = qualifyActionType();
      return {...state, activeRequests: state.activeRequests + 1 };
 
    case '[UI] DECREMENT_LOADING':
      action.type = qualifyActionType();
      return state.activeRequests > 0
        ? {...state, activeRequests: state.activeRequests - 1 }
        : state;
 
    case '[UI] FOUR0FOUR_MESSAGE':
      action.type = qualifyActionType();
      return {...state, four0four: action.payload.four0four };
 
    default:
      return state;
  }
 
  function qualifyActionType() {
    return action.type + ' / ' + (action.trigger ? action.trigger.toLowerCase() : '');
  }
 
};