All files / redux is-app-fetching.js

100% Statements 10/10
100% Branches 9/9
100% Functions 4/4
100% Lines 9/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      2x       2x             2x               7x   2x             5x         2x   2x   2x        
import { createSelector } from 'reselect'
 
// action type
export const TOGGLE_IS_APP_FETCHING = 'TOGGLE_IS_APP_FETCHING'
 
// action
export function toggleAppFetching (error) {
  return {
    type: TOGGLE_IS_APP_FETCHING,
    payload: error || null,
    error: !!error
  }
}
 
const intitialState = {
  isAppFetching: false,
  payload: null,
  error: false
}
 
// reducer
function isAppFetchingReducer (state = intitialState, action) {
  switch (action.type) {
    case TOGGLE_IS_APP_FETCHING:
      return {
        ...intitialState,
        isAppFetching: !state.isAppFetching,
        payload: action.payload || null,
        error: action.error || false
      }
    default:
      return state
  }
}
 
// selector
const isAppFetchingSelector = (state) => state.isAppFetching
 
export const getFetching = createSelector(
  isAppFetchingSelector,
  (isAppFetchingState) => isAppFetchingState
)
 
export default isAppFetchingReducer