-
Notifications
You must be signed in to change notification settings - Fork 0
/
react.gleam
48 lines (40 loc) · 1.18 KB
/
react.gleam
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
pub type Element =
#(String, Props, String)
pub type Prop =
#(String, String)
pub type Props =
List(Prop)
pub fn create_element(tag: String) -> Element {
let props: Props = []
let element: Element = #(tag, props, "")
element
// for now, there is no filter, so people can create any element
// need to figure out a more elegant way to avoid overwriting
// existing dom elements and completely avoiding using some, eg. <marquee>
//
// when implemented: will have to change return to Result(Element, String)
//
// let valid_element = ["html", "body", "div", "span", "p"]
// case list.contains(valid_element, tag) {
// True -> {
// let element: Element = #(tag, props, children)
// Ok(element)
// }
// False -> Error("error")
// }
}
pub fn prop(element: Element, prop: #(String, String)) -> Element {
let #(tag, mut_props, children) = element
let updated_props = [prop, ..mut_props]
#(tag, updated_props, children)
}
pub fn children(element: Element, children: String) -> Element {
let #(tag, props, _) = element
#(tag, props, children)
}
pub fn render(element: Element) -> Element {
element
}
pub fn jsx(markup: String) {
markup
}