Sha256: 27f39ba2aa320f9cf49230811156abb328908df876db09917be6392003d60c95

Contents?: true

Size: 1.17 KB

Versions: 12

Compression:

Stored size: 1.17 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() {
    this.backbonify(this.props)
  },

  componentWillReceiveProps(nextProps) {
    this.backbonify(nextProps)
  },

  backbonify(props) {
    this.__bb = []

    _.each(this.backboneMap, (klass, name) => {
      let data = props[name]

      if(data != null && !(data instanceof Backbone.Model || data instanceof Backbone.Collection)) {
        // Rewrite the prop as the correct Backbone model or collection.
        props[name] = new klass(data)
      }

      // Save a reference so we can wire up events.
      this.__bb.push(props[name])
    })
  },

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

  // Clean up any dangling references when the component is destroyed.
  componentWillUnmount() {
    _.each(this.__bb, (model) => {
      model.off(null, null, this)
    })
  },
  
})

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
revelry_core-0.1.24.0 app/assets/javascripts/revelry/mixins/BackboneProps.es6
revelry_core-0.1.23.0 app/assets/javascripts/revelry/mixins/BackboneProps.es6
revelry_core-0.1.22.0 app/assets/javascripts/revelry/mixins/BackboneProps.es6
revelry_core-0.1.21.0 app/assets/javascripts/revelry/mixins/BackboneProps.es6
revelry_core-0.1.20.0 app/assets/javascripts/revelry/mixins/BackboneProps.es6
revelry_core-0.1.19.0 app/assets/javascripts/revelry/mixins/BackboneProps.es6
revelry_core-0.1.18.0 app/assets/javascripts/revelry/mixins/BackboneProps.es6
revelry_core-0.1.17.0 app/assets/javascripts/revelry/mixins/BackboneProps.es6
revelry_core-0.1.16.0 app/assets/javascripts/revelry/mixins/BackboneProps.es6
revelry_core-0.1.15.0 app/assets/javascripts/revelry/mixins/BackboneProps.es6
revelry_core-0.1.14.0 app/assets/javascripts/revelry/mixins/BackboneProps.es6
revelry_core-0.1.13.0 app/assets/javascripts/revelry/mixins/BackboneProps.es6