jamesmacaulay/react-bacon — pull request #7 by fson (2014-07-15 15:17:02+00:00)
Title: Add `onValue()` method for binding event handlers

In our use of React and Bacon it's been a common use case to add handlers to some external stream (e.g. a `Bacon.Bus` passed to the component in props). These handlers must be unsubscribed when the component unmounts, which would typically result in tedious code like this:
```js
componentWillMount: function () {
this._fooUnsubscribe = this.props.bus.filter(/*...*/).onValue(this.foo);
this._barUnsubscribe = this.props.bus.map(/*...*/).onValue(this.bar);
this._bazUnsubscribe = stream.onValue(this.baz);
},
componentWillUnmount: function () {
this._fooUnsubscribe();
this._barUnsubscribe();
this._bazUnsubscribe();
}
```

This pull request adds method `onValue()` to `BaconMixin` that can be used to add handlers that will automatically be unsubscribed when the component unmounts, allowing the previous example to be rewritten as:
```js
componentWillMount: function () {
this.onValue(this.props.bus.filter(/*...*/), this.foo);
this.onValue(this.props.bus.map(/*...*/), this.bar);
this.onValue(stream, this.baz);
}
```