const React = require('react/addons'); const IntermediateBinder = React.createClass({ displayName: 'IntermediateBinder', propTypes: { boundArg: React.PropTypes.any.isRequired, children: React.PropTypes.func.isRequired, }, _rebindFns(props, bindAll) { const newFns = {}; for (const name in props) { const value = props[name]; if (name !== 'boundArg' && name !== 'children') { if (bindAll || value !== this.props[name]) { newFns[name] = value.bind(null, props.boundArg); } else { newFns[name] = this._boundFns[name]; } } } this._boundFns = newFns; }, componentWillMount() { this._rebindFns(this.props, true); }, componentWillReceiveProps(nextProps) { this._rebindFns(nextProps, this.props.boundArg !== nextProps.boundArg); }, render() { return this.props.children(this._boundFns); }, }); module.exports = IntermediateBinder;