Skip to content

Commit

Permalink
Merge pull request #372 from HapticX/dev
Browse files Browse the repository at this point in the history
component event @created -> @beforeCreated, add a new @created
  • Loading branch information
Ethosa authored Nov 6, 2024
2 parents 646a72a + f709452 commit 8d583fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 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
12 changes: 10 additions & 2 deletions 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 @@ -112,7 +113,8 @@ else:
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 +359,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 8d583fd

Please sign in to comment.