Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. //Step 1
  2. const h = ComponentClass =>
  3. class extends ComponentClass {
  4. h = curry((fn, event) => {
  5. this.setState(fn(this.state, event))
  6. })
  7. }
  8.  
  9. export default h(class extends Component {
  10. state = { count: 0 }
  11. // convert to arrow after bugfix
  12. render() {
  13. return <div>
  14. <button onClick={this.h(update)}>Increment</button>
  15. {this.state.count}
  16. </div>
  17. }
  18. })
  19.  
  20.  
  21. //Step 2
  22. export default @h class extends Component {
  23. state = { count: 0 }
  24. // convert to arrow after bugfix
  25. render() {
  26. return <div>
  27. <button onClick={this.h(update)}>Increment</button>
  28. {this.state.count}
  29. </div>
  30. }
  31. }
  32.  
  33. //Step 3
  34. const h = curry((logger, ComponentClass) =>
  35. class extends ComponentClass {
  36. h = curry((fn, event) => {
  37. logger()
  38. this.setState(fn(this.state, event))
  39. })
  40. })
  41.  
  42.  
  43. export default @h(() => console.log('whoa')) class extends Component {
  44. state = { count: 0 }
  45. // convert to arrow after bugfix
  46. render() {
  47. return <div>
  48. <button onClick={this.h(update)}>Increment</button>
  49. {this.state.count}
  50. </div>
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement