spoike/refluxjs — pull request #73 by krawaller (2014-09-14 09:00:39+00:00)
Title: adding Reflux.connect

After several iterations, I think I've arrived at a good convenience method for the common use case when you want to make a React component set its state to whatever a listenable returns.

This pull request exposes `Reflux.connect(datastore,[stateKey])`, intented to be used as a mixin much like `Reflux.listenTo`. If `stateKey` is supplied then it will do `setState({:data})`, otherwise just `setState(data)`.

Here's the `Reflux.listenTo` example from the README:

```javascript
var Status = React.createClass({
mixins: [Reflux.listenTo(statusStore,"onStatusChange")],
onStatusChange: function(status) {
this.setState({
currentStatus: status
});
},
render: function() {
// render specifics
}
});
```

...which using `Reflux.connect` instead can be reduced to this:

```javascript
var Status = React.createClass({
mixins: [Reflux.connect(statusStore,"currentStatus")],
render: function() {
// render specifics
}
});
```

Isn't it beatiful? Absolutely nothing boilerplaty whatsoever! :)

I found in my `Reflux` app I could almost always use `Reflux.connect` as it was only in very rare cases that I needed to do some special logic.