How to work with sagas?
Closed this issue · 2 comments
mrpsiho commented
First, would like to say that it is a brilliant idea and implementation! Thanks!
Second, would like to point to the mistake in the docs. Instead of:
sagas: {
fetchData: function* (duck) {
try{
yield put({ type: duck.types.FETCH_PENDING })
const payload = yield call(Get, 'data')
yield put({
type: duck.types.FETCH_FULFILLED,
payload
})
} catch(err) {
yield put({
type: duck.types.FETCH_FAILURE,
err
})
}
}
},
it should be:
sagas: (duck) => ({
fetchData: function* (duck) {
try{
yield put({ type: duck.types.FETCH_PENDING })
const payload = yield call(Get, 'data')
yield put({
type: duck.types.FETCH_FULFILLED,
payload
})
} catch(err) {
yield put({
type: duck.types.FETCH_FAILURE,
err
})
}
}
}),
which means that sagas
should be a function that returns object.
Third, I have an issue with firing sagas. Maybe there something else we should know about how to make it work? I am using it with React, in Redux dev tools I see that event for async action is dispatched with the right arguments, but this does not trigger the related function generator.
What should be the problem?
ghondar commented
mrpsiho commented
Thanks!
Your answer was helpful!