Skip to content

Instantly share code, notes, and snippets.

@dantenovski
Created August 20, 2017 19:03
Show Gist options
  • Save dantenovski/fdc52405360289d2626706c02342196c to your computer and use it in GitHub Desktop.
Save dantenovski/fdc52405360289d2626706c02342196c to your computer and use it in GitHub Desktop.
// 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