Created
February 19, 2020 06:50
-
-
Save ikabirov/71c9052ab73a11d8d171b468f82924c6 to your computer and use it in GitHub Desktop.
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
/** @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