https://kotlinlang.org logo
Title
c

Cherrio LLC

02/19/2023, 5:02 PM
Hello, how can i use the
renderProperty
, to change the value of textField? When I try, I get:
n

Nick

02/19/2023, 5:17 PM
Hey. I’m not at a computer to check, but I think the issue is the property needs to be a member of a
View
class. You’re defining this as a local member. Try moving the declaration out of init:
val view = object: View() {
    var time by renderProperty(initial: "")

    init {
    }
}
Also,
renderProperty
will trigger a rerender of the
View
it belongs to whenever that property is changed. So you only need it if you want to repaint the view. Otherwise you can use an observable instead. It fires whenever the property changes.
val view = object: View() {
    var time by observable(initial: "") { old, new ->
    }

    init {
    }
}
Also,
observable
doesn’t have to be a property of a
View
. So it’s more flexible.
c

Cherrio LLC

02/19/2023, 6:10 PM
So how does it know when to rerender?
n

Nick

02/19/2023, 6:20 PM
renderProperty is just an
observable
that calls rerender whenever it is changed. it then calls the block you pass to it to let you do more stuff.
observable
calls it’s callback whenever you set a new value that isn’t equal to the current one. So
renderProperty
is like doing:
object: View() {
    var property by observable(initial) { old,new ->
        rerender()
        …
    }
}
This works because
observable
will call the block whenever
property
is changed