-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.scala
99 lines (85 loc) · 2.15 KB
/
Main.scala
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package Main
import com.raquo.laminar.api.L.{*, given}
import org.scalajs.dom
import scala.scalajs.js
import js.JSConverters.*
import scala.scalajs.js.annotation.*
import util.control.Exception.*
import com.raquo.laminar.nodes.ParentNode
import com.raquo.airstream.state.Var
object Element {
@JSExportTopLevel("nameVar")
val nameVar: Var[String] = {
js.`import`.meta.hot.accept(() => {})
Var(initial = "OwO")
}
@JSExportTopLevel("element")
val element: HtmlElement = {
val elNode = div(
label("Your name: "),
input(
onMountFocus,
placeholder := "Enter your name here",
onInput.mapToValue --> nameVar,
value <-- nameVar
),
span(
"Hello, ",
child.text <-- nameVar.signal.map(_.toUpperCase)
)
)
js.`import`.meta.hot.accept((newModule: js.Dynamic) => {
val newElNode: HtmlElement =
newModule.$t_LMain_Element$__element.asInstanceOf
elNode.maybeParent.map(p =>
ParentNode.replaceChild(
p,
elNode,
newElNode
)
)
val newNameVar: Var[String] =
newModule.$t_LMain_Element$__nameVar.asInstanceOf
newNameVar.set(
allCatch
.opt(js.`import`.meta.hot.data.namedVar.asInstanceOf[String])
.getOrElse("123")
)
})
js.`import`.meta.hot.dispose(() => {
js.`import`.meta.hot.data.namedVar = nameVar.now()
})
elNode
}
}
object Element2 {
@JSExportTopLevel("nameVar2")
val nameVar: Var[String] = {
js.`import`.meta.hot.accept(() => {})
Var(initial = "OwO")
}
@JSExportTopLevel("element2")
val element: HtmlElement = {
val elNode = div(
label("Your name: "),
input(
onMountFocus,
placeholder := "Enter your name here",
onInput.mapToValue --> nameVar,
value <-- nameVar
),
span(
"Hello, ",
child.text <-- nameVar.signal.map(_.toUpperCase)
)
)
elNode
}
}
object App {
@JSExportTopLevel("mount")
def mount(): Unit = {
val appContainer = dom.document.querySelector("#app")
render(appContainer, div(Element.element, Element2.element))
}
}