all files / src/ collection.cjsx

100% Statements 11/11
100% Branches 2/2
100% Functions 2/2
100% Lines 11/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45                                                                11× 11× 11×   11×  
 
React = require('react')
Backbone = require('backbone')
_ = require('underscore')
SelectableCollection = require('selectable-collection')
 
ContextualData = require('./contextualData')
 
 
# see ./collection.md
module.exports = class Collection extends ContextualData
  @displayName: "react-datum.Collection"
 
  # this is the class of thing being placed in the context.
  dataType:  Backbone.Collection
  # this is the key in @context children should use to access thing
  contextKey: 'collection'
 
  @collectionPropType: React.PropTypes.oneOfType([
    React.PropTypes.instanceOf(Backbone.Collection)
    React.PropTypes.array
  ])
 
  @propTypes: _.extend {}, ContextualData.propTypes,
    # can only accept collection via prop.  Collection component should
    # not interfere with any parent Collection commponent or other that
    # would provide a collection context, but it will become the provider
    # of collection context for all of it's children
    collection: @collectionPropType.isRequired
 
 
  @childContextTypes: _.extend {}, ContextualData.childContextTypes,
    collection: @collectionPropType
 
 
  # override - adds SelectableCollection mixin to collection if it doesn't already
  #    have it
  setCollectionOrModel: () ->
    super
    collection = @state.collectionOrModel  # for clarity
    unless !collection? || collection.hasSelectableCollectionMixin
      SelectableCollection.applyTo(collection)
 
    return collection