January 2016
Intermediate to advanced
278 pages
4h 53m
English
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); ...Read now
Unlock full access