Coder Social home page Coder Social logo

acq_q1530667's Introduction

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

acq_q1530667's People

Contributors

jeromegn avatar dwt avatar scott-w avatar nekman avatar andreypopp avatar ryan-roemer avatar joemcelroy avatar dy avatar toddbranch avatar paulmillr avatar juhovh avatar eush77 avatar dremora avatar uzikilon avatar eastridge avatar snappedtogrid avatar marcelklehr avatar kmiyashiro avatar schickling avatar basicallydan avatar fluxusfrequency avatar 4vanger avatar marlun78 avatar nbergseng avatar rsskga avatar renfredxh avatar richardchen331 avatar rbu avatar ssorallen avatar ryangreenberg avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.