Giter Club home page Giter Club logo

backbonedemo's Introduction

BackFire

BackFire is an officially supported Backbone binding for Firebase. The bindings let you use a special Collection type that will automatically synchronize all models contained within it to Firebase, without the need to make explicit calls to save or sync.

Live Demo: Real-time TODO app.

Usage

Include both firebase.js and backbone-firebase.js in your application.

<script src="https://cdn.firebase.com/v0/firebase.js"></script>
<script src="backbone-firebase.js"></script>

There are two primary ways to use the bindings:

METHOD 1: Backbone.Firebase.Collection

You will have access to a new object, Backbone.Firebase.Collection. You may extend this object, and must provide a Firebase URL or a Firebase reference as the firebase property. For example:

var TodoList = Backbone.Firebase.Collection.extend({
  model: Todo,
  firebase: "https://<your-firebase>.firebaseio.com"
});

You may also apply a limit or some other query on a reference and pass it in:

var Messages = Backbone.Firebase.Collection.extend({
  firebase: new Firebase("https://<your-firebase>.firebaseio.com").limit(10)
});

Any models added to the collection will be synchronized to the provided Firebase. Any other clients using the Backbone binding will also receive add, remove and changed events on the collection as appropriate.

BE AWARE! The important difference between using a regular collection and a Firebase collection is that you do not need to call any functions that will affect remote data. If you call fetch or sync on the collection, the library will ignore it silently.

You should add and remove your models to the collection as your normally would, (via add and remove) and remote data will be instantly updated. Subsequently, the same events will fire on all your other clients immediately.

Please see todos.js for an example of how to use this special collection object.

METHOD 2: Backbone.sync

The bindings also override Backbone.sync to use Firebase. You may consider this option if you want to maintain an explicit seperation between local and remote data.

This adapter works very similarly to the localStorage adapter used in the canonical Todos example. You simply provide a firebase property in your Model or Collection, and that object will be persisted at that location.

For example:

var TodoList = Backbone.Collection.extend({
  model: Todo,
  firebase: new Backbone.Firebase("https://<your-namespace>.firebaseio.com")
});

will ensure that any calls to fetch or sync on the collection will update the provided Firebase with the appropriate data. The same is true for the save and destroy methods on a model.

Please see todos-sync.js for an example of how to use this feature.

License

MIT.

backbonedemo's People

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.