Sha256: 8851760c31b15401de2093982bf088e4e36d0826a925ec29a0b7539e037f1c53

Contents?: true

Size: 1.06 KB

Versions: 46

Compression:

Stored size: 1.06 KB

Contents

Rev.registerMixin 'BackboneProps',
  # Component should contain a map of prop names to Backbone classes, like:
  #
  # backboneMap:
  #   users: User.Collection

  # Set up our Backbone instance objects.
  componentWillMount: ->
    @backbonify(@props)

  componentWillReceiveProps: (nextProps)->
    @backbonify(nextProps)

  backbonify: (props)->
    @__bb = []
    for name of @backboneMap
      data = props[name]
      if data? && data? && !(data instanceof Backbone.Model || data instanceof Backbone.Collection)
        # Rewrite the prop as the correct Backbone model or collection.
        klass = @backboneMap[name]
        props[name] = new klass(data)
      # Save a reference so we wire up events.
      @__bb.push props[name]

  # Whenever there may be a change in the Backbone data, trigger a reconcile.
  componentDidMount: ->
    _.each @__bb, (model) =>
      model.on 'all', @forceUpdate.bind(this, null), this

  # Clean up any dangling references when the component is destroyed.
  componentWillUnmount: ->
    _.each @__bb, (model) =>
      model.off null, null, this

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
revelry_core-0.1.9.1 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.9.0 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.8.6 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.8.5 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.8.4 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.8.3 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.8.2 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.8.1 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.8.0 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.7.0 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.6.8 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.6.7 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.6.6 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.6.5 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.6.4 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.6.3 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.6.2 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.6.1 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.5 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.4 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee