forked from HapticX/happyx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testjs16.nim
182 lines (149 loc) · 3.5 KB
/
testjs16.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import
../src/happyx,
random
randomize()
component withRandom:
n: int = rand(99)
`template`:
tDiv: "self random: {self.n.val}"
tDiv: "random in template: {rand(99)}"
var counter: int = 0
var counter2: int = 0
proc nextCounter(c: var int = counter): int =
c += 1
result = c
component withCounter:
count: int = nextCounter()
`template`:
tDiv: "self count: {self.count}"
tDiv: "count in template: {nextCounter(counter2)}"
component withReps:
n: int
`template`:
for i in 1..self.n:
tDiv(style="border: 0.2em dotted gray;"):
slot
component withRepsSquared:
n: int = 2
`template`:
withReps(2):
slot
component A[T]:
value: T
html:
tDiv:
"value is {self.value}"
when self.value is State[string]:
tP:
"Hello, value is string"
tDiv:
slot
component Some[T: int | float, A, B: string]:
value: T
x: A
y: B
`template`:
tDiv:
tP: "Some value is {self.value}"
tP: "Some x,y is {self.x},{self.y}"
component B of A[int]:
html:
tDiv:
"["
super()
"]"
# declare path params
pathParams:
paramName int: # assign param name
optional # param is optional
default = 100 # default param value is 100
type counterObject* = ref object
count*: int
settings*: string
var counterObj1* = counterObject.new()
var counterObj2* = counterObject.new()
proc nextCounter*(c: counterObject): int =
c.count += 1
result = c.count
component withCounterObject:
counter: counterObject = counterObj1
count: int = nextCounter(counter)
`template`:
tDiv: "self count: {self.count}"
tDiv: "count in template: {nextCounter(counterObj2)}"
var index = 0
proc newIndex(): int =
result = index
index += 1
type refIndex = ref object
value*: int
var rindex = refIndex(value:0)
var sindex = refIndex(value:0)
var tindex = refIndex(value:0)
var uindex = refIndex(value:0)
proc nextIndex(r: refIndex): int =
result = r.value
r.value += 1
proc newIndexByRef(): int =
result = rindex.value
rindex.value += 1
component Index:
index: int = newIndex()
Rindex: int = newIndexByRef()
myRefIndex: refIndex = sindex
Sindex: int = myRefIndex.nextIndex()
html:
tDiv: "my index is {self.index}"
tDiv(style="color:purple"): "my refIndex is {self.Rindex}"
tDiv(style="color:orange"): "my internal refIndex is {self.Sindex}"
tDiv(style="color:green"): "my refIndex from the main body is {uindex.nextIndex()}"
component Copypasta:
n: int
html:
for i in 1..self.n.val:
slot
component ShowNum:
n: int
html:
tSpan(style="color:green"): "{self.n.val:04}"
script:
echo self.uniqCompId
randomize()
appRoutes "app":
"/":
for i in 1..5:
withCounterObject
component withReps(5):
withCounter()
withRandom()
"non-component rand {rand(99)}"
component withRepsSquared(2):
"non-component rand {rand(99)}"
"/<paramName>":
{paramName}
"/compsT":
tDiv:
A[int](5)
A[seq[int]](@[1, 2, 3, 4])
A[string]("hello"):
"im a slot"
Some[int, string, string](5, "0", "1")
B(5)
"/issue244":
Index
Index
Index
for i in 1..3:
tDiv(style="color:green"):
"call from route: {tindex.nextIndex()}"
"/issue245":
Copypasta(4):
for i in 1..3:
let n = rand(9999)
tDiv:
tSpan:
"{n:04} = "
ShowNum(n)
nim:
echo inCycle, ", ", inComponent
echo cycleCounter, ", ", compName, ", ", compCounter