Giter Site home page Giter Site logo

hoodie-plugin-backbone's Introduction

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

hoodie-plugin-backbone's People

Contributors

gr2m avatar

Stargazers

telegram-clibot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11/getMe avatar Luiz Américo avatar

Watchers

Laurens Nienhaus avatar James Cloos avatar Tobias Hartmann avatar  avatar

Forkers

nintra

hoodie-plugin-backbone's Issues

require('backbone') or not?

Right now Backbone is required and gets bundled into /_api/_files/hoodie.js. I tend to remove that and expect that backbone.js has been loaded before hoodie.js, so it can be used in hoodie.backbone.js without the require statement.

Also, this would work around this bug: hoodiehq/hoodie-server#281 (comment)

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.