mozilla/localForage — pull request #207 by ahbeng (2014-07-15 11:32:20+00:00)
Title: Async setup and checking for driver support

This involves quite a fundamental change to library initialization, so I'm submitting for review of the implementation to see if it's going in the right direction before writing tests/documentation.

It stems from another attempt to fix the same IndexedDB InvalidStateError in Firefox private browsing as in issues #70 and #195. Some of my users had reported the error even outside of private browsing, with 'Remember history' turned on. Instead of simply rejecting, it would be good if localForage itself could detect during initialization and fallback on localStorage.

However, as mentioned in the [#195 comment](https://github.com/mozilla/localForage/issues/195#issuecomment-47991870), it seems that it is not possible to achieve this with synchronous init. Hence, I've gone with the approach of making init asynchronous, then changing `setDriver()` and `ready()` to wait for the `localForage._driverSupportSet` promise to be fulfilled.

To avoid breaking existing API, this also requires the changes in the earlier commit to call library methods only when ready. This has the additional benefit of rendering `ready` unnecessary when using with RequireJS, which seems useful on its own, so I could split it out to a separate PR later on.

The only possibly breaking API change would be to `localForage.supports`, which could potentially be called externally before `driverSupport` is populated. However, it seems to be undocumented and only for internal use?