Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

backbone.browserStorage

jcbrand1920.0.5

A localStorage and sessionStorage adapter for Backbone. It's a drop-in replacement for Backbone.Sync() to handle saving to the browser's browserStorage or sessionStorage database.

backbone, browserStorage, localStorage, local, sessionStorage, session, storage, cache, sync

readme

Backbone localStorage and sessionStorage adapter

A localStorage and sessionStorage adapter for Backbone. It's a drop-in replacement for Backbone.Sync() to handle saving to the browser's browserStorage or sessionStorage database.

Usage

Include Backbone.browserStorage after having included Backbone.js:

<script type="text/javascript" src="backbone.js"></script>
<script type="text/javascript" src="backbone.browserStorage.js"></script>

Create your collections like so:

window.SomeCollection = Backbone.Collection.extend({

  // For localStorage, use BrowesrStorage.local.
  browserStorage: new Backbone.BrowserStorage.session("SomeCollection"), // Unique name within your app.

  // ... everything else is normal.

});

RequireJS

Include RequireJS:

<script type="text/javascript" src="lib/require.js"></script>

RequireJS config:

require.config({
    paths: {
        jquery: "lib/jquery",
        underscore: "lib/underscore",
        backbone: "lib/backbone",
        browserstorage: "lib/backbone.browserStorage"
    }
});

Define your collection as a module:

define("SomeCollection", ["browserstorage"], function() {
    var SomeCollection = Backbone.Collection.extend({
        // For localStorage, use BrowserStorage.local.
        browserStorage: new Backbone.BrowserStorage.session("SomeCollection") // Unique name within your app.
    });

    return SomeCollection;
});

Require your collection:

require(["SomeCollection"], function(SomeCollection) {
  // ready to use SomeCollection
});

CommonJS

If you're using browserify.

Install using npm install backbone.browserstorage, and require the module.

Backbone.BrowserStorage = require("backbone.browserstorage");

Acknowledgments

This package is a fork of jeromegn's Backbone.localStorage

changelog

Changelog

0.0.5 (2018-10-28)

  • Pass along the options map. Otherwise events fire even though {silent: true} was passed to the Collection.prototype.create method.

0.0.4 (2018-10-21)

  • Don't return boolean on update and create, otherwise the model.changed attribute isn't correctly populated when a model is saved. [jcbrand]

0.0.3 (2016-08-31)

  • 1 Fix typo in main. Fixes webpack failing to load the module [sww314]

  • 2 Fix storage clearing problems [Martinique]

0.0.2 (2015-12-04)

  • Bugfix. undefined is not a function. [jcbrand]

0.0.1 (2015-11-15)

  • Add the ability to also use the browser's sessionStorage instead of just localStorage.
  • Fork from backbone.localStorage