YASAN
02/06/2022, 11:05 AMDominaezzz
02/06/2022, 11:51 AMYASAN
02/06/2022, 11:51 AMfun ActiveStationItem(
stationNullable: Station?,
isPlaying: Boolean,
playState: Int?,
onTogglePlay: () -> Unit
) {
}
I have these paramsDominaezzz
02/06/2022, 11:52 AMYASAN
02/06/2022, 11:52 AMDominaezzz
02/06/2022, 11:54 AMYASAN
02/06/2022, 11:55 AMDominaezzz
02/06/2022, 11:57 AMAdam Powell
02/06/2022, 2:18 PMState<T>
and MutableState<T>
generally shouldn't appear in parameter lists. If you really find yourself in a place where you need more granular invalidations from performing a snapshot read more locally, use a () -> T
instead[Mutable]State<T>
in parameter lists discourages single source of truth vs the alternatives, and breaks usage of the property delegatesYASAN
02/06/2022, 3:06 PMmattinger
02/06/2022, 4:23 PMAdam Powell
02/06/2022, 4:32 PMclass Foo {
var someValue by mutableStateOf(...)
// ...
}
class Bar(
private val foo: Foo
) {
val computedValue: Int
get() = foo.someValue * 2
}
bar.computedValue
?
@Composable
fun BazOne(
value: () -> Int
)
@Composable
fun BazTwo(
value: State<Int>
)
With the first it's just BazOne({ bar.computedValue })
. With the second it's
BazTwo(
object : State<Int> {
override val value: Int
get() = bar.computedValue
}
)
Stylianos Gakis
03/02/2023, 11:37 AMI keep meaning to add it to the compose API guidelines doc and make sure we get a lint check;Has this ever made it anywhere in the official docs so far?andState<T>
generally shouldn’t appear in parameter lists. If you really find yourself in a place where you need more granular invalidations from performing a snapshot read more locally, use aMutableState<T>
instead() -> T