Created
August 20, 2017 19:03
-
-
Save dantenovski/fdc52405360289d2626706c02342196c 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 () { | |
const response = yield call(fetch, "http://haha.com/fetch_1") | |
const data = yield call([response, response.json]) | |
const number = parseInt(data) | |
console.log(number) | |
return number | |
} | |
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