Last active
          July 17, 2019 18:47 
        
      - 
      
- 
        Save jonasantonelli/9ed180d5340e4f93c94a1e33e302ee8d to your computer and use it in GitHub Desktop. 
    Refactoring Reducer - Second Version
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import schema from './schema'; | |
| import { ACTIONS } from './action'; | |
| export default (state = schema, action) => { | |
| switch (action.type) { | |
| case ACTIONS.FETCHING_LIST: | |
| return { | |
| ...state, | |
| list: { | |
| value: [], | |
| fetching: true | |
| } | |
| }; | |
| case ACTIONS.FETCHING_HEADER: | |
| return { | |
| ...state, | |
| header: { | |
| value: {}, | |
| fetching: true | |
| } | |
| }; | |
| case ACTIONS.FETCHING_ITEM: | |
| return { | |
| ...state, | |
| selected: { | |
| value: {}, | |
| fetching: true | |
| } | |
| }; | |
| case ACTIONS.UNSELECT_ITEM: | |
| return { | |
| ...state, | |
| selected: { | |
| value: {}, | |
| fetching: false | |
| } | |
| }; | |
| case ACTIONS.FETCH_LIST_COMPLETE: | |
| return { | |
| ...state, | |
| list: { | |
| value: action.list, | |
| fetching: false | |
| } | |
| }; | |
| case ACTIONS.FETCH_ITEM_COMPLETE: | |
| return { | |
| ...state, | |
| selected: { | |
| value: action.value, | |
| fetching: false | |
| } | |
| }; | |
| case ACTIONS.FETCH_HEADER_COMPLETE: | |
| return { | |
| ...state, | |
| header: { | |
| value: action.value, | |
| fetching: false | |
| } | |
| }; | |
| case ACTIONS.ERROR: | |
| return { | |
| ...state, | |
| isError: true, | |
| errorMessage: action.errorMessage | |
| }; | |
| case ACTIONS.POSTING: | |
| return { | |
| ...state, | |
| isPosting: true | |
| }; | |
| case ACTIONS.CREATED: | |
| return { | |
| ...state, | |
| isPosting: false | |
| }; | |
| case ACTIONS.UPDATED: | |
| return { | |
| ...state, | |
| isPosting: false | |
| }; | |
| default: | |
| return state; | |
| } | |
| }; | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment