forked from HapticX/happyx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testjs18.nim
159 lines (129 loc) · 2.91 KB
/
testjs18.nim
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import ../src/happyx
import std/asyncjs
let htmlProcs = lazyHtmls:
html:
tSpan: "front"
html:
tSpan: "back"
let htmlTags = buildHtmls:
html:
tSpan: "right"
html:
tSpan: "left"
htmlTags[1].eventListener("click"):
echo 1
htmlTags[1].click()
let promise = withPromise res:
withTimeout 1000, t:
clearTimeout(t)
echo "timeout"
{.emit: "res(true)".}
component FormatProcHtml:
p: (proc (): TagRef) # parentheses needed in avoid "nested statements" error
html:
em(style="color:blue"):
{self.p()}
component FormatTagHtml:
t: TagRef
html:
em(style="color:blue"):
{self.t.val}
proc testAsync() {.async.} =
echo "Hello"
component PlainDiv:
html:
tDiv:
slot
var counter: int = 0
proc nextCount(): int =
counter += 1
result = counter
component ShowNextCount:
count: int = nextCount()
html:
{self.count}
" "
{self.uniqCompId}
proc countFactory(): TagRef = buildHtml:
{nextCount()}
proc countComponentFactory(): TagRef = buildHtml:
ShowNextCount
var testCounter = remember 0
testCounter.watch(old, new):
echo "set testCounter from ", old, " to ", new
let A = buildHtml:
tSvg(viewBox="0 0 240 80"):
ttText(x="35",y="20", style="fill: black;"): "A: Anyone Here?"
let B = buildHtml:
tSvg(viewBox="0 0 240 80"):
tText(x="35",y="20", style="fill: black;"): "B: Anyone Here?"
let C = buildHtml:
tSvg(viewBox="0 0 240 80"):
text(x="35",y="20", style= "fill: black;"): "C: Anyone Here?"
component Hello:
html:
tDiv:
"hello"
let b = buildHtml:
Hello
let c = buildHtml:
tDiv:
"hello"
appRoutes("app"):
"/":
tDiv: {$b}
tDiv:
{$c}
c
for i in 1..5:
tDiv:
{$htmlProcs[0]()}
@click:
discard await sleepAsyncJs(500)
discard await testAsync()
FormatProcHtml(htmlProcs[1])
for i in 1..5:
tDiv:{$htmlTags[0]}
FormatTagHtml(htmlTags[1])
{$A}
{A}
{$B}
{B}
{$C}
{C}
"/issues/304":
"in a div"
tDiv:
tDiv(class="no-print", id="trial1"):
"hello"
tDiv(id="trial2", class="no-print"):
"hello again"
tDiv(id="trial2", class="no-print", style="color: red"):
"hello again"
"in a component slot that goes into a div"
PlainDiv():
tDiv(class="no-print", id="trial1"):
"hello"
tDiv(id="trial2", class="no-print"):
"hello again"
tDiv(id="trial2", class="no-print", style="color: red"):
"hello again"
"/issues/303":
"counts as lazies:"
for i in 1..5:
tDiv: countFactory()
"counts as components in lazies:"
nim: counter = 0
for i in 1..5:
for j in 1..2:
tDiv: countComponentFactory()
"counts with just the components"
nim: counter = 0
for i in 1..5:
tDiv: ShowNextCount
"/watchers":
{testCounter}
tButton:
"increase testCounter"
@click:
testCounter += 1