I would like to know if it is possible to return successively-yielded values as an array when the generator is done. This is what I have tried so far, where I add a return statement at the end of the generator and attempt to destructure the output:
function ajax(url) {
fetch(url).then(data => data.json()).then(data => dataGen.next(data))
}
function* steps() {
const beers = yield ajax('http://api.react.beer/v2/search?q=hops&type=beer');
const wes = yield ajax('https://api.github.com/users/wesbos');
const fatJoe = yield ajax('https://api.discogs.com/artists/51988');
return [beers, wes, fatJoe]
}
const dataGen = steps();
const [beers, wes, fatJoe] = dataGen.next(); // kick it off
However, none of the values are returned:
Uncaught ReferenceError: beers is not defined
Uncaught ReferenceError: wes is not defined
Uncaught ReferenceError: fatJoe is not defined