/
ElementFactory.re
59 lines (56 loc) · 1.18 KB
/
ElementFactory.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
open Dom;
open ElementsTypes;
let defaultHandler = _ => ();
let generateNode =
(
~name: nodeName,
~text="",
~id,
~_class,
~style,
~key,
~value="",
~action="",
~method="",
~href="",
~onClick,
~onChange=defaultHandler,
~onInput=defaultHandler,
~onSubmit=defaultHandler,
~children,
~_type="",
(),
)
: node => {
let r = {
name,
text,
position: 0,
attributes: [
("id", id),
("class", _class),
("style", style),
("key", key),
("type", _type),
("value", value),
("href", href),
("method", method),
("action", action),
],
handlers: [
("click", onClick !== defaultHandler ? Some(onClick) : None),
("change", onChange !== defaultHandler ? Some(onChange) : None),
("input", onInput !== defaultHandler ? Some(onInput) : None),
("submit", onSubmit !== defaultHandler ? Some(onSubmit) : None),
],
children,
};
children
|> List.iter(child => {
if (child.name != TEXT) {
r.position = r.position + child.position;
};
r.position = r.position + 1;
});
r;
};