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 mainView = new ShopView shop.owner, petListView mainView.render()
Now we'll update PetListView
to use this new argument:
class window.PetListView constructor: (@views, featuredPets) -> @featured = featuredPets render: -> @renderList...