Skip to content

Instantly share code, notes, and snippets.

@adomado
Created April 8, 2011 18:59
Show Gist options
  • Select an option

  • Save adomado/910498 to your computer and use it in GitHub Desktop.

Select an option

Save adomado/910498 to your computer and use it in GitHub Desktop.

Revisions

  1. adomado created this gist Apr 8, 2011.
    60 changes: 60 additions & 0 deletions spinal_cord.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    $(function() {

    // Model
    window.FeedItemModel = Backbone.Model.extend({

    initialize : function(id, graph) {
    this.id = id;
    this.graph = graph;
    },

    like : function() {
    // Like this feedItem
    },


    comment : function(message) {
    // comment on this feed item
    }
    });



    // Collection
    window.FeedListCollection = Backbone.Collection.extend({
    model : FeedItemModel,
    localStorage : new Store("feed"),

    items : function() {
    // returns all feedItems
    }
    });
    window.FeedItems = new FeedListCollection;



    // View
    window.FeedListView = Backbone.View.extend({

    tagName : "li",
    className : "feed-item",

    initialize : function(feedItemsCollection) {
    feedItemsCollection.bind("add", this.render);
    },

    render : function(feedItem) {
    $("#feed-items").append("<li>" + feedItem.get("graph") + "</li>");
    return this;
    }
    });


    window.App = new FeedListView(FeedItems);

    FeedItems.add(new FeedItemModel({graph : "abc"}));
    FeedItems.add(new FeedItemModel({graph : "def"}));
    FeedItems.add(new FeedItemModel({graph : "ghi"}));
    FeedItems.create({graph : "foo"});

    });