IndexedDB in Backbone
As the IndexedDB API is more complex than localStorage, it will be more difficult to create an IndexedDB driver for Backbone as we did with localStorage; in this section, you will use what you have learned about IndexedDB in order to build a driver for Backbone.
The driver should open a database and initialize the stores when it is created for the first time:
// indexedDB/dataStore.js 'use strict'; var Backbone = require('backbone'); const ID_LENGTH = 10; var contacts = [ // ... ]; class DataStore { constructor() { this.databaseName = 'contacts'; } openDatabase() { var defer = Backbone.$.Deferred(); // If a database connection is already active use it, // otherwise open a new connection if (this.db) { defer.resolve(this.db); } else { let request = indexedDB.open(this.databaseName, 1); request.onupgradeneeded = () => { let db = request.result; this.createStores(db); }; request.onsuccess = () => { // Cache recently...