I'm very new to redux-saga and am reading through the documentation. One of the things I'm not understanding is what, specifically, the API calls return.
When I say "return", I suppose I'm asking two things
what is the return value of what the documentation calls the "factory function"? (that is, here https://redux-saga.js.org/docs/advanced/Testing.html the docs state that "Since Sagas always yield an Effect, and these effects have simple factory functions (e.g. put, take etc.)", what, in general, would be the return values of these factory functions?
what is the return value of these "factory functions" when
yield
ed to the redux-saga middleware?
For instance, in the documentation (https://redux-saga.js.org/docs/advanced/Concurrency.html) they have
import {fork, take} from "redux-saga/effects"
const takeEvery = (pattern, saga, ...args) => fork(function*() {
while (true) {
const action = yield take(pattern)
yield fork(saga, ...args.concat(action))
}
})
I understand, from looking at it, that here take
when yield
ed returns the action
that matches the pattern. Thus I take that to always be the return value. So that here (https://redux-saga.js.org/docs/advanced/NonBlockingCalls.html)
function* loginFlow() {
while (true) {
const {user, password} = yield take('LOGIN_REQUEST')
const token = yield call(authorize, user, password)
if (token) {
yield call(Api.storeItem, {token})
yield take('LOGOUT')
yield call(Api.clearItem, 'token')
}
}
}
user
and password
are fields in the returned action?
But where is this documented, that take
, when yield
ed, returns the action? I went to the documentation for take
, and while there's a fairly good description of what it does, I didn't see what it returns.
In general, is there some underlying assumption about the API calls and their return values that I'm missing, due to my newbie status? Or -- and this is a distinct possibility -- I may simply have overlooked where it mentions the return value.
Thanks for any insights -- and if you know of a good alternative, thorough overview of redux-saga, I'd welcome any links. I've been poring through tutorials and blog posts, but would love a good in-depth look.
take
---gen.next(action).value
--- and that's what I see happening. SImilarly, I believe that if youcall
a function, the middleware will pass the return value of that function back on the nextyield
. But is any/all of this documented anywhere? – Witting