Created
November 28, 2018 20:53
-
-
Save mvbattan/a41a8e5a7b2f7a1386155a38b267fac8 to your computer and use it in GitHub Desktop.
External actions usage
This file contains hidden or 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
import { createActions, createExternalActions } from 'redux-recompose'; | |
// Our action names, as always. These will be handled by our reducer. | |
export const actions = createActions(['LOCAL_ACTION'], '@@SOCCER'); | |
// External actions names being handled by the invisible reducer. We should specify | |
// what slice of the state is related with this reducer, say, state.soccer | |
// No need to handle them at our reducer. | |
const $ = createExternalActions('soccer'); | |
const actionCreators = { | |
getMatches = () => async dispatch => { | |
dispatch({ type: $.LOADING, target: 'matches' }); | |
const response = await SoccerService.getMatches(); | |
if (response.ok) { | |
dispatch({ type: $.SUCCESS, target: 'matches', payload: response.data }); | |
} else { | |
dispatch({ type: $.FAILURE, target: 'matches', payload: response.problem }); | |
} | |
} | |
}; | |
export default actionCreators; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment