backbone-shard / demo.html

Full commit
<!DOCTYPE html>
    <title>Shard Demo</title>
    <link href="" rel="stylesheet">
    <script src=""></script>
    <script src=""></script>
    <script src=""></script>
    <script src="backbone.shard.js"></script>
    <div class="row-fluid">
      <div class="span3 offset5">
        <div id="collection"></div>
    <div class="row-fluid">
      <div class="span3 offset3">
        <div id="subset-read" class="centered"></div>
      <div class="span3 offset1">
        <div id="subset-unread" class="centered"></div>
      var Book = Backbone.Model;
      var col = new Backbone.Collection([
        new Book({title: 'Crime and Punishment', read: true}),
        new Book({title: 'Robinson Crusoe', read: true}),
        new Book({title: 'Moby Dick', read: false}),
        new Book({title: 'The Catcher in the Rye', read: false})
      var CollectionView = Backbone.View.extend({
        initialize: function(options) {
          this.collection.on('add change remove reset', this.render, this);
        render: function() {
          this.collection.each(this.appendItem, this);
        appendItem: function(item) {
          var $cb = $('<input>').attr('type', 'checkbox').prop('checked', item.get('read'));
          var $label = $('<label>').addClass('checkbox').text(item.get('title')).prepend($cb);
          $cb.change(function() {
            item.set('read', this.checked);
      var shardRead = new Backbone.Shard({collection: col, filter: function(book) { return book.get('read'); } });
      var shardUnread = new Backbone.Shard({collection: col, filter: function(book) { return !book.get('read'); } });
      new CollectionView({
        el: $('#collection'),
        collection: col
      new CollectionView({
        el: $('#subset-unread'),
        collection: shardUnread
      new CollectionView({
        el: $('#subset-read'),
        collection: shardRead