Skip to content

Commit

Permalink
v3.11.0 (#267 from HapticX/dev)
Browse files Browse the repository at this point in the history
v3.11.0 - functional components
  • Loading branch information
Ethosa authored May 12, 2024
2 parents 58ec46c + 2868370 commit 7968036
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 7 deletions.
2 changes: 1 addition & 1 deletion happyx.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

description = "Macro-oriented asynchronous web-framework written with ♥"
author = "HapticX"
version = "3.10.2"
version = "3.11.0"
license = "MIT"
srcDir = "src"
installExt = @["nim"]
Expand Down
4 changes: 2 additions & 2 deletions src/happyx/core/constants.nim
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ const
nim_2_0_0* = (NimMajor, NimMinor, NimPatch) >= (2, 0, 0)
# Framework version
HpxMajor* = 3
HpxMinor* = 10
HpxPatch* = 2
HpxMinor* = 11
HpxPatch* = 0
HpxVersion* = $HpxMajor & "." & $HpxMinor & "." & $HpxPatch


Expand Down
53 changes: 49 additions & 4 deletions src/happyx/private/macro_utils.nim
Original file line number Diff line number Diff line change
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,21 @@ proc buildHtmlProcedure*(root, body: NimNode, inComponent: bool = false,
ident"_anonymousTag"
)
else:
newCall("tag", statement[0])
statement[0]
),
newNimNode(nnkElifBranch).add(
newCall(
"and",
newCall("declared", compName),
newCall("is", compName, newNimNode(nnkProcTy)),
), newStmtList(
block:
var call = newCall(compName)
for i in statement[1..^2]:
call.add(i)
call.add(newNimNode(nnkExprEqExpr).add(ident"stmt", newCall("buildHtml", statement[^1])))
call
)
),
newNimNode(nnkElifBranch).add(
newCall(
Expand Down Expand Up @@ -734,7 +748,25 @@ proc buildHtmlProcedure*(root, body: NimNode, inComponent: bool = false,
whenStmt[0].add(useComponent(compStatement, inCycle, inComponent, cycleTmpVar, compTmpVar, cycleVars, constructor = true))
# Component default constructor
else:
whenStmt[0].add(useComponent(compStatement, inCycle, inComponent, cycleTmpVar, compTmpVar, cycleVars))
whenStmt[0].add(
newNimNode(nnkWhenStmt).add(
newNimNode(nnkElifBranch).add(
newCall(
"and",
newCall("declared", compName),
newCall("is", compName, newNimNode(nnkProcTy)),
), newStmtList(
block:
var call = newCall(compName)
for i in statement[1..^1]:
call.add(i)
call
)
), newNimNode(nnkElse).add(
useComponent(compStatement, inCycle, inComponent, cycleTmpVar, compTmpVar, cycleVars)
)
)
)

result.add(whenStmt)

Expand Down Expand Up @@ -1127,7 +1159,20 @@ 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(
"and",
newCall("declared", compName),
newCall("is", compName, newNimNode(nnkProcTy)),
), newStmtList(
block:
var call = newCall(compName)
call
)
),
newNimNode(nnkElifBranch).add(
newCall("not", newCall("is", compName, ident"typedesc")),
Expand Down
12 changes: 12 additions & 0 deletions tests/index17.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div id="app"></div>
<div>
</div>
<script src="testjs17.js"></script>
</body>
</html>
60 changes: 60 additions & 0 deletions tests/testjs17.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import
../src/happyx,
std/macros


var someValue = remember 0

proc funcComp1(i: State[int], stmt: TagRef): TagRef =
## You can pass any amount of arguments.
buildHtml:
tDiv:
"i is "
{i}
@click:
i += 1
stmt

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

# 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}"


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

0 comments on commit 7968036

Please sign in to comment.