Created
February 22, 2021 20:04
-
-
Save AllGistsEqual/bcb96e1889f7f8a52724246ef417c223 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
// File: src/redux/ducks/article.ts | |
export const articleMiddleware: Middleware = ({ dispatch, getState }) => next => action => { | |
next(action) | |
if (requestArticlesData.match(action)) { | |
const state = getState() | |
if (!(state.article && state.article.status === 'pending')) { | |
dispatch(apiRequest({ | |
url: '/articles', | |
method: 'GET', | |
onSuccess: data => storeArticlesData(data), | |
onError: error => cancelArticlesRequest(error) | |
})) | |
dispatch(setArticlesStatus('pending')) | |
} | |
} | |
if (cancelArticlesRequest.match(action)) { | |
const { error } = action.payload | |
console.log("Error while requesting articles: ", error) // eslint-disable-line no-console | |
dispatch(setArticlesStatus('idle')) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment