Skip to content
This repository
Browse code

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

Add itemView instead of getView in CollectionView.
  • Loading branch information...
commit 6693e6336f8240078e4fdecb77facf51d05f8bc0 2 parents b94ee90 + 6c5a83c
Paul Miller authored June 13, 2012

Showing 1 changed file with 10 additions and 4 deletions. Show diff stats Hide diff stats

  1. 14  src/chaplin/views/collection_view.coffee
14  src/chaplin/views/collection_view.coffee
@@ -44,6 +44,10 @@ define [
44 44
     # If empty, all children of $list are considered
45 45
     itemSelector: null
46 46
 
  47
+    # A class of item in collection.
  48
+    # This property has to be overridden by a derived class.
  49
+    itemView: null
  50
+
47 51
     # Filtering
48 52
     # ---------
49 53
 
@@ -60,14 +64,14 @@ define [
60 64
     visibleItems: null
61 65
 
62 66
     # Returns an instance of the view class
63  
-    # This method has to be overridden by a derived class.
64 67
     # This is not simply a property with a constructor so that
65 68
     # several item view constructors are possible depending
66 69
     # on the item model type.
67 70
     getView: (model) ->
68  
-      throw new Error 'CollectionView#getView must be overridden'
69  
-      # Example:
70  
-      # new SomeItemView model: model
  71
+      if @itemView?
  72
+        new @itemView({model})
  73
+      else
  74
+        throw new Error 'CollectionView#itemView must be overridden'
71 75
 
72 76
     # In contrast to normal views, a template is not mandatory
73 77
     # for CollectionViews. Provide an empty `getTemplateFunction`
@@ -84,6 +88,8 @@ define [
84 88
         renderItems: true # Render all items immediately per default
85 89
         filterer: null    # No filter function
86 90
 
  91
+      @itemView = options.itemView if options.itemView?
  92
+
87 93
       # Initialize lists for views and visible items
88 94
       @viewsByCid = {}
89 95
       @visibleItems = []

0 notes on commit 6693e63

Please sign in to comment.
Something went wrong with that request. Please try again.