Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

backbone.localstorage

Package Overview
Dependencies
Maintainers
2
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

backbone.localstorage

[![Build Status](https://travis-ci.org/jeromegn/Backbone.localStorage.svg?branch=master)](https://travis-ci.org/jeromegn/Backbone.localStorage) [![Coverage Status](https://coveralls.io/repos/github/jeromegn/Backbone.localStorage/badge.svg?branch=master)](

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10K
increased by8.46%
Maintainers
2
Weekly downloads
 
Created
Source

Backbone localStorage Backend

Build Status Coverage Status npm version

An adapter that replaces Backbone.sync to save to window.localStorage instead of to the server.

Note Backbone LocalStorage v2 changes the API to work more with ES6 modules. See Upgrade Notes for more details.

Usage

Import backbone.localstorage and attach it to your models and collections:

import {Collection, Model} from 'backbone';
import {LocalStorage} from 'backbone.localstorage';

const SomeCollection = Collection.extend({

  localStorage: new LocalStorage('SomeCollection'), // Uniquely identify this

});

const SomeModel = Model.extend({

  localStorage: new LocalStorage('SomeModel')

});

To synchronise with the server, you can pass the ajaxSync flag to any options:

const myModel = new SomeModel();
myModel.fetch({
  ajaxSync: true  // Fetches from the server
});

myModel.save({
  new: "value"
}, {
  ajaxSync: true  // Pushes back to the server
});

Upgrade Notes

Backbone LocalStorage is now built using ES6. It should be fully compatible with v1 with one difference: Instead of exporting the LocalStorage class as a default module, v2 exports it as a named variable. Below are examples covering the changes:

JavaScript ES5

In v1:

var LocalStorage = require('backbone.localstorage');

In v2:

var localStorage = require('backbone.localstorage');
var LocalStorage = localStorage.LocalStorage;

JavaScript ES6+

In v1:

import LocalStorage from 'backbone.localstorage';

In v2:

import {LocalStorage} from 'backbone.localstorage';

Contributing

Install NodeJS and run yarn or npm i to get your dependencies, then:

  1. Open an issue identifying the fault
  2. Provide a fix, with tests demonstrating the issue
  3. Run npm test
  4. Create a pull request

Acknowledgments

Keywords

FAQs

Package last updated on 28 Apr 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc