Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event handler doesn't update when DOM elements are deleted #35

Closed
bluenote10 opened this issue Jun 25, 2017 · 0 comments
Closed

Event handler doesn't update when DOM elements are deleted #35

bluenote10 opened this issue Jun 25, 2017 · 0 comments

Comments

@bluenote10
Copy link
Contributor

I'm currently dealing with issues which come down to the following behavior. Small example with dynamic deletes from a closure event handler:

include karaxprelude

var elements = @[cstring"A", cstring"B", cstring"C", cstring"D", cstring"E"]

proc renderElement(text: cstring, index: int): VNode =

  kout(cstring"re-building closure for", text, index)
  proc remove(ev: Event, n: VNode) =
    kout(cstring"Deleting element from index: ", index)
    elements.delete(index)

  result = buildHtml():
    tdiv(onClick=remove):
      text text

proc buildDom(): VNode =
  result = buildHtml():
    tdiv:
      for index, text in elements.pairs:
        renderElement(text, index)

setRenderer buildDom

The initial render shows elements A B C D E. Clicking on C correctly says Deleting element from index: 2 and the sequence becomes A B D E. From the log output I can see that the VNodes + closures should have been updated correctly. However, clicking e.g. again on the item on index 2 (now the D) produces the log message Deleting element from index: 3, resulting in the wrong element to be deleted. Since the index 3 is D's old index, it looks like the event handler hasn't been updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant