Skip to content

Commit 7968036

Browse files
authored
v3.11.0 (#267 from HapticX/dev)
v3.11.0 - functional components
2 parents 58ec46c + 2868370 commit 7968036

File tree

5 files changed

+124
-7
lines changed

5 files changed

+124
-7
lines changed

happyx.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
description = "Macro-oriented asynchronous web-framework written with ♥"
44
author = "HapticX"
5-
version = "3.10.2"
5+
version = "3.11.0"
66
license = "MIT"
77
srcDir = "src"
88
installExt = @["nim"]

src/happyx/core/constants.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ const
9494
nim_2_0_0* = (NimMajor, NimMinor, NimPatch) >= (2, 0, 0)
9595
# Framework version
9696
HpxMajor* = 3
97-
HpxMinor* = 10
98-
HpxPatch* = 2
97+
HpxMinor* = 11
98+
HpxPatch* = 0
9999
HpxVersion* = $HpxMajor & "." & $HpxMinor & "." & $HpxPatch
100100

101101

src/happyx/private/macro_utils.nim

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ proc buildHtmlProcedure*(root, body: NimNode, inComponent: bool = false,
676676
),
677677
if statement[^1].kind == nnkStmtList:
678678
newStmtList(
679-
newVarStmt(ident"_anonymousTag", newCall("tag", statement[0])),
679+
newVarStmt(ident"_anonymousTag", statement[0]),
680680
newCall(
681681
"add",
682682
ident"_anonymousTag",
@@ -688,7 +688,21 @@ proc buildHtmlProcedure*(root, body: NimNode, inComponent: bool = false,
688688
ident"_anonymousTag"
689689
)
690690
else:
691-
newCall("tag", statement[0])
691+
statement[0]
692+
),
693+
newNimNode(nnkElifBranch).add(
694+
newCall(
695+
"and",
696+
newCall("declared", compName),
697+
newCall("is", compName, newNimNode(nnkProcTy)),
698+
), newStmtList(
699+
block:
700+
var call = newCall(compName)
701+
for i in statement[1..^2]:
702+
call.add(i)
703+
call.add(newNimNode(nnkExprEqExpr).add(ident"stmt", newCall("buildHtml", statement[^1])))
704+
call
705+
)
692706
),
693707
newNimNode(nnkElifBranch).add(
694708
newCall(
@@ -734,7 +748,25 @@ proc buildHtmlProcedure*(root, body: NimNode, inComponent: bool = false,
734748
whenStmt[0].add(useComponent(compStatement, inCycle, inComponent, cycleTmpVar, compTmpVar, cycleVars, constructor = true))
735749
# Component default constructor
736750
else:
737-
whenStmt[0].add(useComponent(compStatement, inCycle, inComponent, cycleTmpVar, compTmpVar, cycleVars))
751+
whenStmt[0].add(
752+
newNimNode(nnkWhenStmt).add(
753+
newNimNode(nnkElifBranch).add(
754+
newCall(
755+
"and",
756+
newCall("declared", compName),
757+
newCall("is", compName, newNimNode(nnkProcTy)),
758+
), newStmtList(
759+
block:
760+
var call = newCall(compName)
761+
for i in statement[1..^1]:
762+
call.add(i)
763+
call
764+
)
765+
), newNimNode(nnkElse).add(
766+
useComponent(compStatement, inCycle, inComponent, cycleTmpVar, compTmpVar, cycleVars)
767+
)
768+
)
769+
)
738770

739771
result.add(whenStmt)
740772

@@ -1127,7 +1159,20 @@ proc buildHtmlProcedure*(root, body: NimNode, inComponent: bool = false,
11271159
"and",
11281160
newCall("declared", statement),
11291161
newCall("is", statement, ident"TagRef")
1130-
), newCall("tag", statement)
1162+
), newStmtList(
1163+
statement
1164+
)
1165+
),
1166+
newNimNode(nnkElifBranch).add(
1167+
newCall(
1168+
"and",
1169+
newCall("declared", compName),
1170+
newCall("is", compName, newNimNode(nnkProcTy)),
1171+
), newStmtList(
1172+
block:
1173+
var call = newCall(compName)
1174+
call
1175+
)
11311176
),
11321177
newNimNode(nnkElifBranch).add(
11331178
newCall("not", newCall("is", compName, ident"typedesc")),

tests/index17.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title></title>
5+
</head>
6+
<body>
7+
<div id="app"></div>
8+
<div>
9+
</div>
10+
<script src="testjs17.js"></script>
11+
</body>
12+
</html>

tests/testjs17.nim

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import
2+
../src/happyx,
3+
std/macros
4+
5+
6+
var someValue = remember 0
7+
8+
proc funcComp1(i: State[int], stmt: TagRef): TagRef =
9+
## You can pass any amount of arguments.
10+
buildHtml:
11+
tDiv:
12+
"i is "
13+
{i}
14+
@click:
15+
i += 1
16+
stmt
17+
18+
# proc funcComp2(i: State[int]): TagRef =
19+
# buildHtml:
20+
# tDiv:
21+
# "comp2, so `i` is {i}"
22+
23+
# proc funcComp3(): TagRef =
24+
# buildHtml:
25+
# tDiv:
26+
# "comp3 without arguments"
27+
28+
proc funcComp4(stmt: TagRef): TagRef =
29+
static:
30+
echo declared(stmt) and stmt is TagRef
31+
buildHtml:
32+
tDiv:
33+
"comp4 with body"
34+
stmt
35+
36+
37+
# component NormalComp:
38+
# i: State[int]
39+
# html:
40+
# tDiv:
41+
# "And this is common component. i is {self.i}"
42+
43+
44+
appRoutes "app":
45+
"/":
46+
tDiv:
47+
# "Here is functional components"
48+
# funcComp1(someValue):
49+
# "This is functional component slot"
50+
# funcComp2(someValue)
51+
# funcComp3()
52+
# funcComp3
53+
funcComp4():
54+
"Hello"
55+
funcComp1(someValue):
56+
"This is functional component slot"
57+
!debugCurrent
58+
# funcComp4:
59+
# "world"
60+
# NormalComp(someValue)

0 commit comments

Comments
 (0)