()
| 2 | |
| 3 | export default (reducer, render) => { |
| 4 | function Machine() { |
| 5 | Component.call(this); |
| 6 | let cache = {}; |
| 7 | let action = type => cache[type] || (cache[type] = data => { |
| 8 | this.setState(reducer(this.state, { type, data, props: this.props })); |
| 9 | }); |
| 10 | this.render = (props, state) => render(state, action); |
| 11 | this.componentWillReceiveProps = action('@@PROPS'); |
| 12 | this.componentWillMount = action('@@INIT'); |
| 13 | } |
| 14 | return (Machine.prototype = new Component()).constructor = Machine; |
| 15 | }; |