Extends a collection's get method to fetch models from the server if not found locally
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.md
backbone.store-collection.js

README.md

Backbone Store Collection

Extends a collection's get method to fetch models from the server if not found locally.

Write ups: Using Backbone.js Class Properties as Data Stores and Part 2

Usage

Posts = Backbone.StoreCollection.extend({
  url: '/posts'
});

var posts = new Posts(),
    post = new Backbone.Model({ id: 1 });
    
posts.add(post);

// Retrieving model from collection
posts.get(1, function() {
  success: function(model, response) {
    // do something with model
  }
});

// Fetching model from server
posts.get(32, function() {
  success: function(model, response) {
    // do something with model
  },
  error: function(model, response) {
    // say sorry
  }
});

Todo

Add tests.

Licence

Backbone Store Collection is copyright © 2012 Dom Christie and released under the MIT license.