-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.re
61 lines (57 loc) · 1.47 KB
/
example.re
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
open ReactFrp.React;
open ReactReact;
open ReactReact.Utils;
module ShowName = {
let vdomS = propsS =>
S.map(
~eq=(_, _) => false,
name =>
if (name != "") {
let greeting = {j|Hello, $name!|j};
<p> {ReasonReact.string(greeting)} </p>;
} else {
<p> {ReasonReact.string("Hello, unknown person!")} </p>;
},
propsS,
);
[@react.component]
let make = (~name) => componentFromSignal(vdomS, name);
};
module Timer = {
let counter = ref(0);
let (timeS, timeF) = S.create(counter^);
let timeIncrement = () => {
counter := counter^ + 1;
timeF(counter^);
};
let timerId = Js.Global.setInterval(timeIncrement, 1000);
let vdomS = _ =>
S.map(
~eq=(_, _) => false,
time => {
let timeMessage = time == 1 ? "second" : "seconds";
let message = {j|You've spent $time $timeMessage on this page!|j};
<div> {ReasonReact.string(message)} </div>;
},
timeS,
);
[@react.component]
let make = () => componentFromSignal(vdomS, ());
};
module Input = {
let (nameS, nameF) = S.create("");
let vdomS = _ =>
S.map(
~eq=(_, _) => false,
name =>
<div>
<input type_="text" onChange={ev => emitEventToStream(nameF, ev)} />
<ShowName name />
<Timer />
</div>,
nameS,
);
[@react.component]
let make = () => componentFromSignal(vdomS, ());
};
ReactDOMRe.renderToElementWithId(<Input />, "index");