superfeedr / indexeddb-backbonejs-adapter

An indexedDB adapter for Backbonejs
http://blog.superfeedr.com/indexeddb-backbonejs-adapter/
MIT License
248 stars 61 forks source link

Fix bug with migration. cleanup code. #36

Closed toots closed 11 years ago

toots commented 11 years ago

Hi,

I've been having a bug where DOM IDBDatabase Exception 11 was being thrown out during my second migration.

Turned out the bug can be fixed by not waiting for transaction.oncomplete to fire next migration.

More specifically, transaction.oncomplete seems to be dependent upon the GC:

The following sentence isn't correct "Transactions today auto-commit when the transaction variable goes out of scope and no more requests can be placed against it".

Since the JS GC sucks really bad, it's always a good idea to keep the transaction variable around if one wants to avoid an unfortunate oncomplete callback. (indeed calling this.transaction will fall out of the GC scope, thus transaction may be considered out of scope..)

I have thus added transaction as the first variable of the migration function. Also, it turned out that migrate was just a proxy for _migrate_next so I've removed _migrate_next.