Cherrio LLC
02/19/2023, 5:02 PMrenderProperty
, to change the value of textField? When I try, I get:Nick
02/19/2023, 5:17 PMView
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 {
}
}
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 {
}
}
observable
doesn’t have to be a property of a View
. So it’s more flexible.Cherrio LLC
02/19/2023, 6:10 PMNick
02/19/2023, 6:20 PMobservable
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