brodysoft/Cordova-SQLitePlugin — pull request #80 by nolanlawson (2014-07-07 17:59:36+00:00)
Title: Fix callback order

This was a really tricky bug to track down, but I've managed to write a failing test and to fix it. This fix actually results in a 100% green run for all 700 tests in the PouchDB test suite (there were roughly a dozen failures before).

The gist of this is that it's not safe to have any callback attached to `db.transaction` execute immediately. Per the spec, the callee should never be blocked. This was playing havoc with the PouchDB tests, because we were using Promises and had made some assumptions about the callback order.

This fix comes in three parts (ignore the commits that are relevant to other PRs):

* d5e6b6e - Add test to demonstrate improper callback order

Adds a unit test that fails for the plugin API but succeeds for the native API, thus demonstrating the incompatibility between the two.

* 4b820d5 - clean up the SQLitePLugin.js file, remove coffeescript

Sorry, but I didn't notice the CoffeeScript file there until I had already made significant changes. I also added a .jshintrc file so that I could actually see errors in my IDE (both Sublime and WebStorm should have this integration). I know this is mostly a cultural thing, but it's your library, so I can only say that my own preference would be to just get rid of the CS and work directly on the JS, especially since we're only talking about ~300 lines of code here, and it makes the build process much simpler (not to mention easier to find contributors :)).

* b9b8a16 - Ensure initial transaction executes in nextTick

The fix itself, which ensures that the transaction doesn't block. If you're curious why I prefer `setImmediate` to `setTimeout`, see [this](http://stackoverflow.com/a/15349865).