Permalink
Browse files

Merge pull request #106 from chaplinjs/topics/collection-view-item-view

Add itemView instead of getView in CollectionView.
  • Loading branch information...
2 parents b94ee90 + 6c5a83c commit 6693e6336f8240078e4fdecb77facf51d05f8bc0 @paulmillr paulmillr committed Jun 13, 2012
Showing with 10 additions and 4 deletions.
  1. +10 −4 src/chaplin/views/collection_view.coffee
@@ -44,6 +44,10 @@ define [
# If empty, all children of $list are considered
itemSelector: null
+ # A class of item in collection.
+ # This property has to be overridden by a derived class.
+ itemView: null
+
# Filtering
# ---------
@@ -60,14 +64,14 @@ define [
visibleItems: null
# Returns an instance of the view class
- # This method has to be overridden by a derived class.
# This is not simply a property with a constructor so that
# several item view constructors are possible depending
# on the item model type.
getView: (model) ->
- throw new Error 'CollectionView#getView must be overridden'
- # Example:
- # new SomeItemView model: model
+ if @itemView?
+ new @itemView({model})
+ else
+ throw new Error 'CollectionView#itemView must be overridden'
# In contrast to normal views, a template is not mandatory
# for CollectionViews. Provide an empty `getTemplateFunction`
@@ -84,6 +88,8 @@ define [
renderItems: true # Render all items immediately per default
filterer: null # No filter function
+ @itemView = options.itemView if options.itemView?
+
# Initialize lists for views and visible items
@viewsByCid = {}
@visibleItems = []

0 comments on commit 6693e63

Please sign in to comment.