Created
April 8, 2011 18:59
-
-
Save adomado/910498 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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