Coder Social home page Coder Social logo

sumavenugopal / localforage-backbone Goto Github PK

View Code? Open in Web Editor NEW

This project forked from localforage/localforage-backbone

0.0 1.0 0.0 153 KB

Backbone.js driver for the localForage offline storage library

License: Other

JavaScript 82.39% HTML 17.61%

localforage-backbone's Introduction

localForage Backbone Build Status

Backbone.js driver for the localForage offline storage library.

Install with bower:

bower install localforage-backbone

Run tests with grunt:

grunt test

Submit issues, pull requests, etc. if something is up! <3

Usage

This library lets you override the sync() method on your collections and models so they're saved to localForage instead of a REST server. Simply override your objects' sync() method with the namespace for your model:

    var MyModel = Backbone.Model.extend({
        sync: Backbone.localforage.sync('MyModel')
    });

    var MyCollection = Backbone.Collection.extend({
        model: MyModel,
        sync: Backbone.localforage.sync('MyCollection')
    });

Now whenever you save your collections or models, they'll be saved with localForage!

Warning

This library is only about overriding Backbone.sync, which means that calling collection.remove(model) won't update the offline storage.

The Backbone.Collection.remove function is only about removing a model from a collection, to clean up all references and event listeners, but does not involve a sync operation.

If you want to destroy a model, you should use this code instead:

// retrieve a model by its id and destroy it
collection.get(id).destroy();

// or

// retrieve a model by its index in the collection and destroy it
collection.at(index).destroy();

License

This program is free software; it is distributed under an Apache License.


Copyright (c) 2014 Mozilla (Contributors).

localforage-backbone's People

Contributors

chatgris avatar iamolivinius avatar magalhas avatar stephanebachelier avatar tofumatt avatar

Watchers

 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.