JSPM

backbone.browserStorage

0.0.5
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 26
  • Score
    100M100P100Q55905F

Package Exports

  • backbone.browserStorage

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (backbone.browserStorage) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

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