Trying a different approach to the project and ran into a wall [SOLVED] - Feedback requested

Hey Hey -
After looking at the previous projects and reviewing the API docs, I decided to approach the project a bit differently. Most are declaring an array with the channels as array elements. In my mind this didn’t seem very useful, so I decided to first use the search api to find a relevant channel (no problem there) and display the results (again, no problem there). I’m having a hell of a time figuring out how to then call the streams api and get the status added to each channel object. I think I need to do something with promises, or deferred objects, but I can’t quite get it…

Here is the pen…
http://codepen.io/chadagate-1471204219/pen/GjRvXN

I’ve removed all of the rendering code, and am just trying to see if I can get the online property added to the array of channel objects… Any advice, hints, or comments are appreciated!

Chad

Hey, the problem is, that calling getJSON (async function) inside your for loop will mess things up. Have a look here: http://stackoverflow.com/questions/11488014/asynchronous-process-inside-a-javascript-for-loop

1 Like

Thanks for that @BenGitter ! I tumbled down a rabbit hole trying to figure that one out, burned up a whole day! I’ll be able to wrap this project up tonight…

1 Like

Okay, I’ve wrapped up my Twitch project. I don’t love the fact that i needed to use setTimeout to get the channels streaming status properties added to the channel objects. It feels like there is a WAY better way to do that. I’m going to spend some time reading about promises and closures in javascript, I believe that may be the better way to get it done. Any feedback is appreciated!

Twitch Project Pen