Skip to content

Instantly share code, notes, and snippets.

@mvbattan
Created November 28, 2018 20:53
Show Gist options
  • Save mvbattan/a41a8e5a7b2f7a1386155a38b267fac8 to your computer and use it in GitHub Desktop.
Save mvbattan/a41a8e5a7b2f7a1386155a38b267fac8 to your computer and use it in GitHub Desktop.
External actions usage
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