Last active
August 19, 2017 23:16
-
-
Save dantenovski/bdff0ec2ea7cf1ac9a2dcae960d9c3a4 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
// sagas.js | |
function* fetchIncrement(){ | |
return fetch(`http://haha.com/fetch_1`) | |
.then(res=>res.json()) | |
.then(data=>{ | |
console.log(parseInt(data)); // returns string "1" and logs 1 as expected | |
return parseInt(data); | |
}).catch(err=>console.log(err)) | |
} | |
export function* incrementAsync(){ | |
const fetchResult = yield call (fetchIncrement); // fetchResult is a Promise object, not 1 | |
yield put({type: 'INCREMENT_COUNT', payload: fetchResult}) // fetchResult needs to be 1 | |
} | |
export function* watchIncrementAsync(){ | |
yield takeEvery('INCREMENT_ASYNC', incrementAsync); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment