deanreinhard/gitber — pull request #1 by mattdunn (2013-02-28 12:41:32+00:00)
Title: loading readme fix

Hey Dean!

So you have the exact same problem I did :)

- The first json call for a given users repos is issued asynchronously, then on completion invokes a callback.
- Inside the callback, for each repo a json call for a readme is issued asynchronously, and then another callback is invoked at some point in time in the future.

So you need to wait until the subsequent callback for the readme is complete before notifying ember of the repo + readme.

This commit gets all the readmes in parallel, then when they're all retrieved iterates through them and tells ember about the repo + readme. On reflection, it could be done one by one instead by shifting the pushObject logic inside the loadRepoReadme method (typically by providing it as a callback for invocation later), but it makes it harder to see in the program structure where things are happening. Defining nested callbacks like this in javascript is known as the "pyramid of doom", which you know from the loading page animation :)

I pulled in the async.js library to do the parallel map call. I like it as you can see the first callback is how to map each element, and the second is what to do when all the elements are mapped.

Its slown down the ui a bit visually, time for some fade in magic :)

Enjoy!