Skip to content

Commit

Permalink
component event @created -> @beforeCreated, add a new @created
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethosa committed Nov 6, 2024
1 parent fb90977 commit 0ab6ff7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/happyx/spa/components.nim
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ macro component*(name, body: untyped): untyped =
]
usedLifeCycles = {
"created": false, # at created
"beforeCreated": false, # at created
"updated": false, # at HTML render end
"rendered": false, # at render/reRender end
"beforeUpdated": false, # before render/reRender
Expand Down Expand Up @@ -825,11 +826,11 @@ macro component*(name, body: untyped): untyped =
newNimNode(nnkIfStmt).add(newNimNode(nnkElifBranch).add(
newCall("==", newDotExpr(ident"self", ident"isCreated"), newLit(false)),
newStmtList(
newCall(newDotExpr(ident"self", ident"created"), ident"self"),
newAssignment(
newDotExpr(ident"self", ident"isCreated"),
newLit(true)
)
newCall(newDotExpr(ident"self", ident"beforeCreated"), ident"self"),
# newAssignment(
# newDotExpr(ident"self", ident"isCreated"),
# newLit(true)
# )
)
))
).add(
Expand Down
9 changes: 8 additions & 1 deletion src/happyx/spa/renderer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ when defined(js):
inCycle: bool, cycleCounter: var int, compCounter: string
): TagRef
slotData*: TagRef
created*: ComponentEventHandler ## Calls before first rendering
beforeCreated*: ComponentEventHandler ## Calls before first rendering
created*: ComponentEventHandler ## Calls after first rendering
exited*: ComponentEventHandler ## Calls after last rendering
rendered*: ComponentEventHandler ## Calls after every rendering
pageHide*: ComponentEventHandler ## Calls after every rendering
Expand Down Expand Up @@ -357,10 +358,16 @@ when defined(js):
components.del(comp.uniqCompId)
for comp in currentComponentsList.mitems:
comp = registerComponent(comp.uniqCompId, comp)
if not comp.isCreated:
comp.created(comp)
comp.isCreated = true
comp.updated(comp, nil)
createdComponentsList.setLen(0)
else:
for comp in currentComponentsList:
if not comp.isCreated:
comp.created(comp)
comp.isCreated = true
comp.updated(comp, nil)
currentComponentsList.setLen(0)
if activeElement.hasAttribute("id"):
Expand Down

0 comments on commit 0ab6ff7

Please sign in to comment.