项目作者: Astrocoders

项目描述 :
CPS sugar usage for React Render Props composition in ReasonML
高级语言: HTML
项目地址: git://github.com/Astrocoders/reason-epitath.git
创建时间: 2018-10-12T05:35:20Z
项目社区:https://github.com/Astrocoders/reason-epitath

开源协议:MIT License

下载


bs-epitath demo

Read the article https://medium.com/astrocoders/render-props-composition-for-reasonml-is-here-b9c004ca9fcb

Running

  1. npm install
  1. npm start
  1. module StateConfig = {
  2. type state = string;
  3. };
  4. /* ReContainers is from https://github.com/Astrocoders/recontainers/ */
  5. module State = ReContainers.WithState.Make(StateConfig);
  6. let component = ReasonReact.statelessComponent("App");
  7. let make = _children => {
  8. ...component,
  9. render: _self => {
  10. let%Epitath emailState = children =>
  11. <State initialState=""> ...children </State>;
  12. <div>
  13. <h1> {ReasonReact.string("Meet Epitath")} </h1>
  14. <label> {ReasonReact.string("Email")} </label>
  15. <input
  16. onChange={
  17. event =>
  18. emailState.send(Set(ReactEvent.Form.target(event)##value))
  19. }
  20. />
  21. <p> {ReasonReact.string(emailState.state)} </p>
  22. {
  23. /* Combine as many as you want. Use even in the middle of JSX! */
  24. let%Epitath passwordState = children =>
  25. <State initialState=""> ...children </State>;
  26. <>
  27. <label> {ReasonReact.string("Password")} </label>
  28. <input
  29. onChange={
  30. event =>
  31. passwordState.send(
  32. Set(ReactEvent.Form.target(event)##value),
  33. )
  34. }
  35. />
  36. <p> {ReasonReact.string(passwordState.state)} </p>
  37. </>;
  38. }
  39. </div>;
  40. },
  41. };

Next Steps

Maybe change

  1. let%Epitath passwordState = children =>
  2. <State initialState=""> ...children </State>;

to

  1. let%Epitath passwordState = <State initialState="" ></State>;