Created
December 1, 2017 15:59
Star
You must be signed in to star a gist
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