npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

backbone-idb

v0.2.8

Published

Backbone IndexedDB adapter with cross browser support via IDBWrapper

Downloads

15

Readme

backbone-idb

Backbone IndexedDB adapter with cross browser support via IDBWrapper

Build Status

IDBWrapper tutorial Part 1 - Basic CRUD

IDBWrapper tutorial Part 2 - Indexes and Query

See tests for usage until I get some more time to fully document.

Dependencies

Obtaining backbone-idb

Available via npm

$ npm install backbone-idb
# or
$ npm install backbone-idb --save # to install and save to package.json

Also available via bower

$ bower install backbone-idb
# or
$ bower install backbone-idb --save # to install and save to bower.json

Usage

Define a Backbone.Model or Backbone.Collection with an indexedDB property in the initialize function.

var Note = Backbone.Model.extend({});

var Notes = Backbone.Collection.extend({
  initialize: function() {
    this.indexedDB = new Backbone.IndexedDB({
      storeName: 'notes',
      dbVersion: 1,
      keyPath: 'id',
      autoIncrement: true,
      indexes:[
        {name:'tags', keyPath:'tags', unique: false, multiEntry: true},
        // When specifying only the `name`, `keyPath` is assummed to be the same.
        // `unique` and `multiEntry` are also false by default.
        // {name:'titleLC', keyPath:'titleLC', unique: false, multiEntry: false}
        {name:'titleLC'}
      ]
    }, this);
  },

  model: Note
});

The first parameter passed into Backbone.IndexedDB is the options object. You may pass in an empty object and have the default attributes set for the store (defaults listed below). Any options that you pass in will override the defaults.

// The default options object set on the Collection/Model
var options = {
  storeName: 'Store',
  storePrefix: '',
  dbVersion: 1,
  keyPath: 'id',
  autoIncrement: true,
  onStoreReady: defaultReadyHandler,
  onError: defaultErrorHandler,
  indexes: []
};

Since indexedDB is asynchronous in nature, we need to update the way we instantiate a new Collection or Model. By default, backbone-idb will trigger idb:ready on the object. This behaviour can be overridden by setting your own callback function on the onStoreReady attribute in the options object.

var notes = new Notes();

notes.once('idb:ready', function() {
  // Some actions to take after initializing the new collection
});

Collections/Models can now use the same Backbone.sync api to interact with IndexedDB; however, you will need to add your own success callback and, optionally, your own error callback in the options parameter.

notes.fetch({success: function() {
  // fetch success handler
}});

var note = new Note();

notes.add(note);
note.save({title: 'some note title'}, {success: function() {
  // save success handler
}});

TODO

  • Document retrieving models from a store by an index via the iterate command
  • Document keyRanges
  • Proxying directly to idb-wrapper via the indexedDB.store object