Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ikabirov
Created February 19, 2020 06:50
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 ikabirov/71c9052ab73a11d8d171b468f82924c6 to your computer and use it in GitHub Desktop.
Save ikabirov/71c9052ab73a11d8d171b468f82924c6 to your computer and use it in GitHub Desktop.
/** @type {PayloadActionCreator<string>} */
const removeItemStarted = declareAction()
/** @type {PayloadActionCreator<string>} */
const removeItemCompleted = declareAction()
/** @type {PayloadActionCreator<string>} */
const removeItemFailed = declareAction()
/**
* @param {string} itemId
* @param {Store} store
*/
async function removeItemImpl(itemId, store) {
store.dispatch(
removeItemStarted(itemId)
)
const api = store.getState(apiAtom)
const itemRemoved = await api.removeItem(itemId)
if (itemRemoved)
{
store.dispatch(
removeItemCompleted(itemId)
)
}
else
{
store.dispatch(
removeItemFailed(itemId)
)
}
}
const removeItem = declareAction(removeItemImpl)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment