Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. /** @jsx h */
  2. import ReactDOM from "react-dom"
  3.  
  4. export const Count = [
  5. ({ state, props }) => ({ value: state.count(Number), color: props.color }),
  6. ({ value, color }, h) => <h2 style={{ color, margin: 0 }}>{value}</h2>
  7. ]
  8.  
  9. export default [
  10. // 1
  11. function mapping({ state }, bitbox) {
  12. return {
  13. count: state.count(String),
  14. set: target => e => bitbox.set(target, state.count, Number(e.target.value || 0)),
  15. inc: target => e => bitbox.set(target, state.count, state.count((c = 0) => c + 1)),
  16. dec: target => e => bitbox.set(target, state.count, state.count((c = 0) => c - 1))
  17. }
  18. },
  19. // 2
  20. function component({ count, inc, dec, set }, h) {
  21. return (
  22. <main>
  23. <div style={{ padding: 16, background: "#f4f4f4" }}>
  24. <Count color="red" />
  25. <input onChange={set} value={count} />
  26. <button onClick={inc}>+</button>
  27. <button onClick={dec}>-</button>
  28. </div>
  29. </main>
  30. )
  31. },
  32. // 3
  33. function render(node) {
  34. ReactDOM.render(node, document.querySelector("#root"))
  35. }
  36. // ...
  37. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement