recipeswithbackbone / recipeswithbackbone.github.com

Marketing site for the best damn backbone.js book evar
23 stars 1 forks source link

Changes feed chapter needs some clarification #42

Closed nareshbhatia closed 12 years ago

nareshbhatia commented 12 years ago

In the changes feed chapter the Collections.AppointmentChanges class refers to this.collection and options.collection (see below). This is confusing. Does this mean that AppointmentChanges collection is initialized with another collection? Does the overall application maintain two collection classes? Could you please clarify the intent, preferably with a working example?

Collections.AppointmentChanges = Backbone.Collection.extend({ model: Models.Appointment, url: "/appointments", initialize: function(models, options) { _.bindAll(this, 'changes', 'processChanges', 'processChange', 'since'); this.collection = options.collection; this.bind('reset', this.processChanges); setInterval(this.changes, 15*1000); }, ... }

ngauthier commented 12 years ago

Hi @nareshbhatia,

Yup, we left out the initialization steps, which would look like:

// Make the main collection
var appointments = new Collections.Appointments();
// Initialize changes feed based on that collection
new Collections.AppointmentChanges({collection: appointments})

the idea here is that the changes feed operates on a given collection. In fact, we could have simplified this further and allowed the model and url to be passed in as well, making it even more flexible.

Hope that helps, let me know if you have more questions. @ngauthier