Skip to content

Commit

Permalink
add reapplyEvents that updates event handlers to point to the new v…
Browse files Browse the repository at this point in the history
…node after diffing (#257)
  • Loading branch information
geotre authored Apr 24, 2023
1 parent b415ce5 commit d0b70a5
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions karax/karax.nim
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ proc applyEvents(n: VNode) =
for i in 0..<len(n.events):
n.events[i][2] = wrapEvent(dest, n, n.events[i][0], n.events[i][1])

proc reapplyEvents(n: VNode) =
removeAllEventHandlers(n.dom)
applyEvents(n)

proc getVNodeById*(id: cstring; kxi: KaraxInstance = kxi): VNode =
## Get the VNode that was marked with ``id``. Returns ``nil``
## if no node exists.
Expand Down Expand Up @@ -394,6 +398,7 @@ proc addPatchV(kxi: KaraxInstance; parent: VNode; pos: int; newChild: VNode) =
proc moveDom(dest, src: VNode) =
dest.dom = src.dom
src.dom = nil
reapplyEvents(dest)
if dest.id != nil:
kxi.byId[dest.id] = dest
assert dest.len == src.len
Expand Down

0 comments on commit d0b70a5

Please sign in to comment.