0.0.5 • Published 9 years ago

ampersand-react-view-mixin v0.0.5

Weekly downloads
7
License
BSD-2-Clause
Repository
github
Last release
9 years ago

Ampersand-ReactView mixin

Use this mixin in your React components to automatically get notified of changes that happen in your Ampersand.js models or collections. It will call the component forceUpdate method whenever a "change" event is triggered in the model properties. There's no need to manually listen to the model and call setState anymore!

It also adds listenTo() and listenToAndRun() methods (Ampersand view style) that will stop listening to the events when the component is unmounted.

Usage

// super-cool-react-view.jsx
var AmpersandReactViewMixin = require('ampersand-react-view-mixin');

module.exports = React.createClass({
  mixins: [AmpersandReactViewMixin],
  
  componentDidMount: function() {
    this.listenToAndRun(this.model, 'change:someProp', this.onSomePropChanged);
  },
  
  render: function() {
    return <div>{this.model.someProp}</div>
  }
  
  onSomePropChanged: function() {
    console.log('awesome!');
  }
});

// another-view.jsx
var SuperCoolReactView = require('super-cool-react-view.jsx');

module.exports = React.createClass({
  render: function() {
    return <SuperCoolReactView model={someModel} />
  }
});
0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago