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
const reducerDescription: { | |
[actions.GET_MATCHES]: onLoading(), | |
[actions.GET_MATCHES_SUCCESS]: onSuccess(), | |
[actions.GET_MATCHES_FAILURE]: onFailure(), | |
[actions.GET_PITCHES]: onLoading(), | |
[actions.GET_PITCHES_SUCCESS]: onSuccess(), | |
[actions.GET_PITCHES_FAILURE]: onFailure(), | |
[actions.INCREMENT_COUNTER]: onAdd() | |
}; |
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
const actionCreators = { | |
fetchSomething: () => composeInjections( | |
baseThunkAction(actions.FETCH, 'fetchTarget', Service.fetch), | |
withPostSuccess(dispatch => dispatch(navigationActions.push('/successRoute'))), | |
withStatusHandling({ 404: dispatch => dispatch(navigationActions.push('/failureRoute')) }) | |
) | |
} | |
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
const actionCreators = { | |
fetchSomething: () => async dispatch => { | |
dispatch({ type: actions.FETCH }); | |
const response = Service.fetch(); | |
if (response.ok) { | |
dispatch({ type: actions.FETCH_SUCCESS, payload: response.data }); | |
dispatch(navigationActions.push('/successRoute'); | |
} else { | |
dispatch({ type: actions.FETCH_ERROR, payload: response.error }); | |
if (response.status === 404) { |
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
import SoccerService from '../services/SoccerService'; | |
export const actions = createTypes(completeTypes['GET_MATCHES','GET_PITCHES'], '@SOCCER'); | |
const actionCreators = { | |
getMatches: () => | |
createThunkAction(actions.GET_MATCHES, 'matches', SoccerService.getMatches), | |
getPitches: clubId => | |
createThunkAction(actions.GET_PITCHES, 'pitches', SoccerService.getPitches, () => clubId) | |
}; |
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
// if action.payload is like: { matches: [] }; | |
const reducerDescription = { | |
// This will store the array of matches instead of the whole object comming from payload | |
[actions.GET_MATCHES_SUCCESS]: onSuccess(action => action.payload.matches) | |
}; |
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
export const actions = createTypes( | |
completeTypes(['GET_MATCHES', 'GET_PITCHES'], ['INCREMENT_COUNTER']), | |
'@@SOCCER' | |
); |
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
const stateDescription = { | |
matches: [], | |
pitches: [], | |
counter: 0 | |
}; | |
const initialState = completeState(stateDescription, ['counter']); |
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
const reducerDescription: { | |
primaryActions: [actions.GET_MATCHES, actions.GET_PITCHES], | |
override: { | |
[actions.INCREMENT_COUNTER]: onAdd() | |
} | |
} | |
export default createReducer(initialState, completeReducer(reducerDescription)) |
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
export function onLoading(selector = (action, state) => true) { | |
return (state, action) => ({ ...state, [`${action.target}Loading`]: selector(action, state) }); | |
} | |
export function onSuccess(selector = (action, state) => action.payload) { | |
return (state, action) => ({ | |
...state, | |
[`${action.target}Loading`]: false, | |
[action.target]: selector(action, state), | |
[`${action.target}Error`]: null |
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
const reducerDescription = { | |
[actions.MATCHES]: onLoading(), | |
[actions.MATCHES_SUCCESS]: onSuccess(), | |
[actions.MATCHES_FAILURE]: onFailure(), | |
[actions.PITCHES]: onLoading(), | |
[actions.PITCHES_SUCCESS]: onSuccess(), | |
[actions.PITCHES_FAILURE]: onFailure() | |
}; | |
export default createReducer(initialState, reducerDescription); |