Dexie v1.4.0-beta
Pre-releaseOptimized, simplified and debug friendlier.
This pre-relase contains an optimized and simplified code base that also is much easier to debug. Please help me test it out.
Long Stacks for Easier Debugging
- Long 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...
// ...
});
Totally Rewritten Promise
The Promise class has been rewritten totally in order to be more optimized and execute all tasks in a virtual microtick engine.
Promise.scheduler = customScheduler;
It is now possible to set a custom scheduler for Promise, like Bluebird's setScheduler(). The scheduler MUST be indexedDB friendly though. Maybe this could be something to use with angular to track digests and maintain scopes.
Dexie.Promise.scheduler = function customScheduler (callback, args) {
$rootScope.$evalAsync(function() {
callback.apply(null, args);
});
};
I have not tested this with angular, so please help me test it. Setting a custom scheduler inactivates the internal virtual micro-tick engine and will always use the provided scheduler to call then-handlers in Promises. When using a custom scheduler, pay attention to whether indexedDB transaction survives your scheduler or not. setTimout() would not survive it. setImmediate() maybe.
Cleaner Code
Dexie.js and its other modules has been revised and some complex methods has been simplified.
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.
Other
- Issue fixed: Promise.on('error') wasn't signaled for rejections outside transactions: e7f3275
- Behave if indexedDB implementatino throws undefined or null: b82be5c
- Wrong class expected in options to Dexie constructor 614a456.
- #130 resolved (No leaking arguments, https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#32-leaking-arguments)
See also pull request #242 which contains most of the changes in this release.