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.12.6 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.12.5 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.12.4 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.12.3 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.12.2 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.12.0 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.11.6 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.11.5 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.11.2 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.11.1 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.11.0 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.10.7 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.10.6 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.10.5 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.10.4 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.10.3 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.10.2 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.10.1 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.10.0 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee
revelry_core-0.1.9.2 app/assets/javascripts/revelry/mixins/BackboneProps.js.coffee