Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
The Activity Stream View in Backbone
var ActivityStreamView = Backbone.View.extend({
el: '#main_stream', // el attaches to existing element
initialize: function(){
_.bindAll(this, 'render', 'appendItem'); // every function that uses 'this' as the current object should be in here
this.collection = new ActivityList();
this.collection.bind('add', this.appendItem); // collection event binder
this.maxSize = 20;
render: function(){
_(this.collection.models).each(function(item){ // in case collection is not empty
}, this);
appendItem: function(item){
var itemView = new ActivityView({ model: item });
if (this.el.children.count > this.maxSize) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment