Skip to content

Instantly share code, notes, and snippets.

@sfrdmn
Created December 1, 2017 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfrdmn/8fa0edb79882f0fcc3154b46b331a24c to your computer and use it in GitHub Desktop.
Save sfrdmn/8fa0edb79882f0fcc3154b46b331a24c to your computer and use it in GitHub Desktop.
mcr_post_06
const fetchFoodItems = createActionCreator(
{
pending: FOOD_ITEMS_FETCH_PENDING,
complete: FOOD_ITEMS_FETCH_COMPLETE,
error: FOOD_ITEMS_FETCH_ERROR,
},
() => () => foodService.fetchFoodItems()
)
const addFoodItem = createActionCreator(
{
pending: FOOD_ITEMS_ADD_PENDING,
complete: FOOD_ITEMS_ADD_COMPLETE,
error: FOOD_ITEMS_ADD_ERROR,
},
// Here's an example where we take advantage of the fact we are wrapping
// totally normal thunk creators by also dispatching within the wrapped thunk
item => dispatch => (
foodService
.addFoodItem(item)
.then((result) => {
dispatch(recordAnalytics({ event: 'OMG_SOMEONES_USING_THE_APP' }))
return result
})
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment