spoike/refluxjs — pull request #59 by krawaller (2014-09-06 14:02:42+00:00)
Title: Adding the ListenerMixinFactory

This pull request adds a `ListenerMixinFactory` shorthand, which creates the `componentDidMount` call for you. Instead of doing this:

```javascript
var myComponent = React.createClass({
mixins: [Reflux.ListenerMixin],
componentDidMount: function() {
this.listenTo(myStore, this.someMethod);
},
// rest redacted
});
```

...you can now do this:

```javascript
var myComponent = React.createClass({
mixins: [Reflux.ListenerMixinFactory(myStore,"someMethod"],
// rest redacted
});
```
Using `this.someMethod` as the second argument won't work, as `this` doesn't point to the instance at this point in time. You can however of course send a callback by reference:

```javascript
var myCallback = function(){
// clever stuff goes here
};

var myComponent = React.createClass({
mixins: [Reflux.ListenerMixinFactory(myStore,myCallback],
// rest redacted
});
```

So really just a small convenience, but it removes some boilerplatey stuff. And I thought it was rather cute. :)