   a
 
 window.MaterialsCollectionClass = React.createClass
+  getDefaultProps: ->
+    randomize: false
+    limit: Infinity
+    header: null
+
   getInitialState: ->
     materials: []
     truncated: true

    )

  render: ->
    (div {},
      (SMaterialsList {materials: @getMaterialsList()})
      @renderTruncationToggle()
    )

window.MaterialsCollection = React.createFactory MaterialsCollectionClass

Portal.renderMaterialsCollection = (collectionId, selectorOrElement, limitOrOptions = Infinity) ->
  # Keep API backward compatible, so accept either 'limit' option as the last argument or hash.
  options = if typeof limitOrOptions == 'number'
              {limit: limitOrOptions}
            else
              limitOrOptions
  ReactDOM.render MaterialsCollection(collection: collectionId, limit: options.limit, randomize: options.randomize),
    jQuery(selectorOrElement)[0]

{div, span, a, i, h1} = React.DOM

shuffle = (a) ->
  idx = a.length
