A final refactoring pass

Now that we've separated our logic and we have a feel for how it all fits together, let's take one more pass through our code looking for things that are out of place. Our first stop is this line, from PetListView#render:

@renderFeatured "Chupa", "Kelsey", "Flops"

The view shouldn't be concerned with the specific pets that are featured. Let's move this out of the view. Our controller (setup.coffee) is a pretty good place for this information. We'll add it to the data object there, and pass it to the PetListView:

shop = {
  owner: new Person "Ian"
  animals: Animal.loadSeedData()
  featured: [ "Chupa", "Kelsey", "Flops" ]
}
petViews = (new PetView pet for pet in shop.animals)
petListView = new PetListView petViews, shop.featured ...

Get CoffeeScript Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.