Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #106 from chaplinjs/topics/collection-view-item-view
Browse files Browse the repository at this point in the history
Add itemView instead of getView in CollectionView.
  • Loading branch information
paulmillr committed Jun 13, 2012
2 parents b94ee90 + 6c5a83c commit 6693e63
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/chaplin/views/collection_view.coffee
Expand Up @@ -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
# ---------

Expand All @@ -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`
Expand All @@ -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 = []
Expand Down

0 comments on commit 6693e63

Please sign in to comment.