What does the following syntax mean? I don’t understand the use of a *
after a yield. I’m new to generators, redux, and sagas, so I would appreciate some help understanding what the syntax *
, takeEvery()
, and the return function *(action) {
do:
var MIDDLEWARES = []
function builder( ) {
const LOAD_DATA = "POI_LOADER/LOAD_POIS"
MIDDLEWARES.push( function *sagaFunction() {
yield *takeEvery( LOAD_DATA, loadData( statusField) )
} )
}
const loadData = (statusField) => {
return function *(action) {
console.log("action.venueId = " + action.venueId)
}
}
There are several questions here:
- What does the
*
inyield *takeEvery()
mean? Seems to be answered by Delegated yield (yield star, yield *) in generator functions. - Why doesn't the builder() function need a
*
to make it a generator given that it contains ayield *
statement? Is that because theyield *takeEvery()
is wrapped in the generator functionsagaFunction()
? - What does the
takeEvery()
function do, especially given that it has a*
in front of it? I thinktakeEvery()
. Based on its documentation, I think it appliesloadData()
to everything inLOAD_DATA
. But ifLOAD_DATA
isn't an array, istakeEvery()
needed in this code? - How come the declaration
return function *(action)
seems to have no name for the function? Is it declaring a generator with input parameteraction
and assigning that generator for aconst
calledloadData
? - Does the Saga library call
next()
on the generators created in this code?