coderly/ember-gdrive — pull request #10 by begedin (2014-11-19 19:09:22+00:00)
Title: A quick and dirty fix for gapi not loading in time for ember-simple-auth

This is related to #9.

This commit is probably not something that should be merged into the main branch, but it makes it work for now, so I can continue work with implementing ember-simple-auth

I'll explain what's going on in the comments below, but here's the gist of it.

The initializer that loads gapi is called `requireGoogleLibraries`.

The load order for initializers in embger-gdrive is as following:

* `'requireGoogleLibraries'`
* `'googleDriveAuth'`
* `'store'`
* `'google-drive'` (set as `after: 'store'`)

`ember-simple-auth` has a single initializer which doesn't set a `before` or `after` option. In the global load order, with nothing changed, it get's loaded Before any of the `ember-gdrive` initializers. That's the **first problem**.

We can fix the load order in a quick and dirty way by doing this:
```
Application.initializer({
name: "googleDriveAuth",
before: ["store", "simple-auth"] // --- THIS IS THE CHANGE RIGHT HERE,
initialize: function(container, application) {
application.register('auth:google', GoogleDriveAuth, {instantiate: false});

application.inject('controller', 'auth', 'auth:google');
application.inject('route', 'auth', 'auth:google');
}
});
```
It still doesn't fix the issue. Here's the `'requireGoogleLibraries'` initializer:
```
Application.initializer({
name: 'requireGoogleLibraries',
before: 'googleDriveAuth',
initialize: function(container, application) {
application.deferReadiness();
loader.load().then(function() {
application.advanceReadiness();
});
}
});
```
That's **the second problem**. It's asynchronous, so **it doesn't block loading of other initializers**. The quick and dirty solution will be commented on below.