Skip to content

Commit

Permalink
upgrade functional components
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethosa committed May 12, 2024
1 parent 24f4356 commit 7561567
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
8 changes: 5 additions & 3 deletions src/happyx/private/macro_utils.nim
Expand Up @@ -676,7 +676,7 @@ proc buildHtmlProcedure*(root, body: NimNode, inComponent: bool = false,
),
if statement[^1].kind == nnkStmtList:
newStmtList(
newVarStmt(ident"_anonymousTag", newCall("tag", statement[0])),
newVarStmt(ident"_anonymousTag", statement[0]),
newCall(
"add",
ident"_anonymousTag",
Expand All @@ -688,7 +688,7 @@ proc buildHtmlProcedure*(root, body: NimNode, inComponent: bool = false,
ident"_anonymousTag"
)
else:
newCall("tag", statement[0])
statement[0]
),
newNimNode(nnkElifBranch).add(
newCall(
Expand Down Expand Up @@ -1159,7 +1159,9 @@ proc buildHtmlProcedure*(root, body: NimNode, inComponent: bool = false,
"and",
newCall("declared", statement),
newCall("is", statement, ident"TagRef")
), newCall("tag", statement)
), newStmtList(
statement
)
),
newNimNode(nnkElifBranch).add(
newCall(
Expand Down
49 changes: 27 additions & 22 deletions tests/testjs17.nim
Expand Up @@ -15,41 +15,46 @@ proc funcComp1(i: State[int], stmt: TagRef): TagRef =
i += 1
stmt

proc funcComp2(i: State[int]): TagRef =
buildHtml:
tDiv:
"comp2, so `i` is {i}"
# proc funcComp2(i: State[int]): TagRef =
# buildHtml:
# tDiv:
# "comp2, so `i` is {i}"

proc funcComp3(): TagRef =
buildHtml:
tDiv:
"comp3 without arguments"
# proc funcComp3(): TagRef =
# buildHtml:
# tDiv:
# "comp3 without arguments"

proc funcComp4(stmt: TagRef): TagRef =
static:
echo declared(stmt) and stmt is TagRef
buildHtml:
tDiv:
"comp4 with body"
stmt


component NormalComp:
i: State[int]
html:
tDiv:
"And this is common component. i is {self.i}"
# component NormalComp:
# i: State[int]
# html:
# tDiv:
# "And this is common component. i is {self.i}"


appRoutes "app":
"/":
tDiv:
"Here is functional components"
funcComp1(someValue):
"This is functional component slot"
funcComp2(someValue)
funcComp3()
funcComp3
# "Here is functional components"
# funcComp1(someValue):
# "This is functional component slot"
# funcComp2(someValue)
# funcComp3()
# funcComp3
funcComp4():
"Hello"
funcComp4:
"world"
NormalComp(someValue)
funcComp1(someValue):
"This is functional component slot"
!debugCurrent
# funcComp4:
# "world"
# NormalComp(someValue)

0 comments on commit 7561567

Please sign in to comment.