Created
December 1, 2017 15:59
-
-
Save sfrdmn/17d2cae7e2f8c4fb8e5dc201764e12d9 to your computer and use it in GitHub Desktop.
mcr_post_08
This file contains 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
const { combineReducers } = require('redux') | |
const foodItemsLoadState = loadStateReducer({ | |
FOOD_ITEMS_FETCH_PENDING: 'pending', | |
FOOD_ITEMS_FETCH_ERROR: 'error', | |
FOOD_ITEMS_FETCH_COMPLETE: 'complete' | |
}) | |
const foodItemAddState = loadStateReducer({ | |
FOOD_ITEMS_ADD_PENDING: 'pending', | |
FOOD_ITEMS_ADD_ERROR: 'error', | |
FOOD_ITEMS_ADD_COMPLETE: 'complete' | |
}) | |
const foodItemAdd = (state, { type, payload }) => { | |
switch (type) { | |
case FOOD_ITEMS_ADD_COMPLETE: | |
return { ...state, data: [ ...state.data, payload ] } | |
default: | |
return state | |
} | |
} | |
const foodItems = (state, action) => ( | |
foodItemAdd(foodItemsLoadState(state, action), action) | |
) | |
const reducer = combineReducers({ | |
foodItems, | |
foodItemAddState | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment