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

KVar receiving incorrect initial value in #65

ethanmdavidson opened this issue Jun 11, 2019 · 1 comment


None yet
2 participants
Copy link

commented Jun 11, 2019

given this code:

fun main(args: Array<String>) {
    val count = KVar(0)

    Kweb(port = 8080) { {
            h1().text({ c -> "Count: $c"})
            button().text("Click me!") {
                count.value += 1
  1. Open the page and click the button a few times (e.g. 4 times)
  2. Reload the page
    Expected behavior: page displays the proper count (e.g. 4)
    Actual behavior: page displays "Count: 0"

The issue is due to the way KVar inherits from KVal. When you create the KVar, the super KVal is created with pValue = 0, and pValue doesn't get updated when the KVar is changed. Then, when you call map(), it returns a new KVal with a listener attached and an initial value of pValue. This can be further demonstrated by initializing the KVar with a different value, e.g. val count = KVar(42). Every time the page is reloaded, it will initially render with 42.

@ethanmdavidson ethanmdavidson added the bug label Jun 11, 2019

@sanity sanity closed this in cf45fa5 Jun 11, 2019


This comment has been minimized.

Copy link

commented Jun 11, 2019

Fix committed + unit test, and released in 0.4.21 - thanks guys!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.