-
-
Notifications
You must be signed in to change notification settings - Fork 641
Dexie.addons
David Fahlander edited this page Apr 16, 2015
·
11 revisions
This array contains functions that extends Dexie. An addon may register itself in Dexie.addons by using Dexie.addons.push(fn)
. Example:
(function(){
function ForEachAddon (db) {
// Makes it possible to use forEach() instead of each() on collections.
db.Collection.prototype.forEach = db.Collection.prototype.each;
}
Dexie.addons.push(ForEachAddon);
})();
If including Dexie as a AMD or CommonJS module, modules will not register themselves automatically.
When using requirejs:
require(['Dexie','Dexie.Observable','Dexie.Syncable'], function (Dexie, dexieObservable, dexieSyncable) {
var db1 = new Dexie('dbname', {
// Always specify explicitely wich addons to include
addons: [dexieObservable, dexieSyncable]
});
var db2 = new Dexie('dbname');
// db2 will have no addons active even though they were required.
});
But when using script includes:
<script src="Dexie.js"></script>
<script src="Dexie.Observable.js"></script>
<script src="Dexie.Syncable.js"></script>
<script>
// db1 will have the addons activated automatically
var db1 = new Dexie('dbname');
// db2 will not have any addons activated
var db2 = new Dexie('dbname', {addons: []});
</script>
Dexie.js - minimalistic and bullet proof indexedDB library