Skip to content

Instantly share code, notes, and snippets.

@adomado
Created April 8, 2011 18:59
Show Gist options
  • Save adomado/910498 to your computer and use it in GitHub Desktop.
Save adomado/910498 to your computer and use it in GitHub Desktop.
$(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"});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment