1.1.1 • Published 9 years ago

hoodie-plugin-backbone v1.1.1

Weekly downloads
16
License
-
Repository
github
Last release
9 years ago

hoodie-plugin-backbone

Backbone bindings for Hoodie

Installation

hoodie install backbone

Usage

The Backbone plugin provides a hoodie.backbone backbone API with two properties:

  1. hoodie.backbone.Model
  2. hoodie.backbone.Collection

When inheriting from the hoodie.backbone Model or Collection, all changes get automagically persisted using hoodie, and changes coming from remote will be passed trough.

Example

var TodoModel = hoodie.backbone.Model.extend({
  type: 'todo'
});
var TodoCollection = hoodie.backbone.Collection.extend({
  model: TodoModel
});
var todos = new TodoCollection();

todos.create({title: 'persisted and synced with Hoodie.', done: true});

Options

type

The type property must be set when inheriting from hoodie.backbone.model

hoodie.filter

By default, a collection automatically reflects all changes coming from remote for the type of its model. If you want it to react to only certain events, a filter function can be passed

var TodoCollection = hoodie.backbone.Collection.extend({
  model: TodoModel,
  hoodie: {
    filter: function(todo) {
      return this.parent.id === todo.listId;
    }
  }
});
var todos = new TodoCollection({parent: list});

If the filter function returns false, the event for the past object will be ignored.

License

MIT

1.1.1

9 years ago

1.1.0

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago