Skip to content

Dexie v1.4.0

Compare
Choose a tag to compare
@dfahlander dfahlander released this 07 Jun 15:25
· 1619 commits to master since this release

Optimized, simplified and debug friendlier.

Much of the code base has been rewritten since v1.3.6 for the purposes of both optimization and code simplification.

Async stacks for Easier Debugging

  • Async stack support on all thrown errors in debug mode.
  • Debug mode is defined via Dexie.debug static property.
  • Dexie.debug will default to true when served from localhost.
Dexie.debug = true; // Enables long stacks (Default on when served from localhost)

db.friends.toArray(friends => {
    return friends.map(friend => friend.name);
}).then (names => {
    console.log(names.join(', ');
}).then (()=> {
    throw new Error ("oops!");
}).catch (function (e) {
    console.error ("Oops: " + e.stack); // Will see long stacks containing async flow:
         // Error: oops!
         //    at yourSource:file:line
         // From previous:
         //    at yourSource of prevous promise
         //    ...
         // From previous:
         //    at yourSrouce even earlier...
         //    ...
});

Reusable Collections

If you prepare a collection:

var collection = db.friends.where('age').above(25);

...you can reuse that collection in any transaction later:

db.transaction('r', db.friends, function() {
    collection.toArray(function (result) {
        console.log(JSON.stringify(result));
    });
});

In previous versions, Collections where bound to the transaction where they were created.

Optimizations

  • Using new indexedDB methods getAll() & getAllKeys when available in IDBObjectStore & IDBIndex.
  • Faster promise implementation. Chaining .then() on returned promises will execute in a virtual micro-tick engine which ensures maximum performance as well as keeping indexedDB transactions alive no matter how long you chains are. Previous version did also keep indexedDB transaction alive, but executed then-handlers in a long and clumsy stack, which failed to comply fully with the A+ spec and made it cumbersome to debug and could theoretically end up in a stack overflow if utilizing very long promise chains.
  • No leaking arguments enables V8 to optimize more code.
  • No dynamic properties on Transaction objects.
  • Fewer layers when accessing a transaction.

Totally Rewritten Promise

The Promise class has been rewritten totally in order to be more optimized and execute all tasks in a virtual indexedDB-compliant microtick engine.

Cleaner Code

Dexie.js and its other modules has been revised and some complex methods has been simplified.

Architectural Changes

  • db.transaction() will now always execute the scope function asynchronically. In previous versions, the scope function could be executed either directly (synchronically) or asynchronically depending on whether the database was ready, or if a parent transaction was locked.
  • Table instances are singletons of WriteableTable now. There's no more need to dynamically generate Table instances when creating a transaction instance because the Table methods will inspect ongoing transaction runtime instead. A future major release (2.0) will likely deprecate WriteableTable and instead incorporate it into class Table, as with WriteableCollection to be incorporated into Collection. Table related properties on Transaction is subject of deprecation as well, since it's returned instances aren't bound to the transaction.

Other

See also pull request #242 which contains most of the changes in this release.

Known Issues

  • Open issues
  • Specifically, this version will trigger this zonejs issue when used together with karma-source-map-support. This is not a Dexie issue, but since Dexie v1.4.0 performs a feature detection by calling new Error().stack at startup, it will fail there if karma-source-map-support and zone.js are loaded.