Skip to content

Commit

Permalink
add scopeSelf for slots
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethosa committed Dec 20, 2023
1 parent cd7f516 commit d0252c5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/happyx/private/macro_utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ proc useComponent*(statement: NimNode, inCycle, inComponent: bool,
newDotExpr(ident(componentName), ident"slot"),
newLambda(
newStmtList(
newVarStmt(ident"self", newDotExpr(ident"self", name)),
newVarStmt(ident"scopeSelf", newDotExpr(ident"scopeSelf", name)),
buildHtmlProcedure(
ident"div", componentSlot, inComponent, ident(componentName), inCycle, cycleTmpVar, compTmpVar, cycleVars
).add(newNimNode(nnkExprEqExpr).add(ident"onlyChildren", newLit(true))),
),
@[ident"TagRef", newIdentDefs(ident"self", ident"BaseComponent")]
@[ident"TagRef", newIdentDefs(ident"scopeSelf", ident"BaseComponent")]
)
),
if returnTagRef:
Expand Down
4 changes: 2 additions & 2 deletions src/happyx/spa/renderer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ when defined(js):
BaseComponentObj* {.inheritable.} = object
uniqCompId*: string
isCreated*: bool
slot*: proc(self: BaseComponent): TagRef
slot*: proc(scopeSelf: BaseComponent): TagRef
created*: ComponentEventHandler ## Calls before first rendering
exited*: ComponentEventHandler ## Calls after last rendering
rendered*: ComponentEventHandler ## Calls after every rendering
Expand All @@ -91,7 +91,7 @@ else:
BaseComponentObj* {.inheritable.} = object
uniqCompId*: string
isCreated*: bool
slot*: proc(self: BaseComponent): TagRef
slot*: proc(scopeSelf: BaseComponent): TagRef
created*: ComponentEventHandler ## Calls before first rendering
exited*: ComponentEventHandler ## Calls after last rendering
rendered*: ComponentEventHandler ## Calls after every rendering
Expand Down
2 changes: 0 additions & 2 deletions tests/index11.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
</head>
<body>
<div id="app"></div>
<div>
</div>
<script src="testjs11.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion tests/testjs11.nim
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var compWithoutArgs = use:

appRoutes "app":
"/":
tScript(type="text/javascript", `defer`=""): """
tScript(type="text/javascript", "defer"=""): """
console.log("Hello from script");
"""
component compWithoutArgs
Expand Down
24 changes: 13 additions & 11 deletions tests/testjs4.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ var

app.routes:
"/":
if darkMode:
tDiv(class="bg-gray-900 text-white px-8 py-24"):
"This page was visited"
else:
tDiv(class="bg-gray-200 text-black px-8 py-24"):
"This page was visited"
tButton:
"Toggle dark mode"
@click:
darkMode.val = not darkMode
echo darkMode
tDiv:
if darkMode:
tDiv(class="bg-gray-900 text-white px-8 py-24"):
"This page was visited"
else:
tDiv(class="bg-gray-200 text-black px-8 py-24"):
"This page was visited"
tButton:
"Toggle dark mode"
@click:
darkMode.val = not darkMode
echo darkMode
application.router()

app.start()

0 comments on commit d0252c5

Please sign in to comment.