Created
February 24, 2017 01:26
-
-
Save StevenTCramer/7a09f1739f4dc17cc25e546bbbd62f89 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
import { createLogic } from 'redux-logic'; | |
import * as actionTypes from './constants'; | |
import {loadInitiation, loadSuccess, loadFailure, loadCancel} from './actionCreators'; | |
const url = 'https://raw.githubusercontent.com/RyanCCollins/scalable-react-ts-boilerplate/master/README.md'; | |
//This logic fails. | |
export const fetchLogic = createLogic({ | |
type: actionTypes.LOAD_INTIATION, | |
cancelType: actionTypes.LOAD_CANCEL, | |
latest: true, // take latest only | |
processOptions: { | |
dispatchReturn: true, | |
successType: actionTypes.LOAD_SUCCESS, | |
failType: actionTypes.LOAD_FAILURE | |
}, | |
process({ httpClient }) { | |
httpClient.get(url) | |
.then(response => response.data); | |
} | |
}); | |
// The below logic works | |
// export const fetchLogic = createLogic({ | |
// type: actionTypes.LOAD_INTIATION, | |
// cancelType: actionTypes.LOAD_CANCEL, | |
// latest: true, // take latest only | |
// process({ getState, action, httpClient }, dispatch, done) { | |
// httpClient.get(url) | |
// .then(response => response.data) | |
// .then(markdown => dispatch({type: actionTypes.LOAD_SUCCESS, payload: markdown })) | |
// .catch(err => { | |
// console.error(err); // log since could be render err | |
// dispatch({ type: actionTypes.LOAD_FAILURE, payload: err, | |
// error: true }) | |
// }) | |
// .then( () => done()); | |
// } | |
// }); | |
export default [ | |
fetchLogic | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment