Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Step 1
- const h = ComponentClass =>
- class extends ComponentClass {
- h = curry((fn, event) => {
- this.setState(fn(this.state, event))
- })
- }
- export default h(class extends Component {
- state = { count: 0 }
- // convert to arrow after bugfix
- render() {
- return <div>
- <button onClick={this.h(update)}>Increment</button>
- {this.state.count}
- </div>
- }
- })
- //Step 2
- export default @h class extends Component {
- state = { count: 0 }
- // convert to arrow after bugfix
- render() {
- return <div>
- <button onClick={this.h(update)}>Increment</button>
- {this.state.count}
- </div>
- }
- }
- //Step 3
- const h = curry((logger, ComponentClass) =>
- class extends ComponentClass {
- h = curry((fn, event) => {
- logger()
- this.setState(fn(this.state, event))
- })
- })
- export default @h(() => console.log('whoa')) class extends Component {
- state = { count: 0 }
- // convert to arrow after bugfix
- render() {
- return <div>
- <button onClick={this.h(update)}>Increment</button>
- {this.state.count}
- </div>
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement