spoike/refluxjs — pull request #75 by krawaller (2014-09-18 06:47:25+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(listenable,[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.