Zoltan Demant
11/03/2023, 6:23 AMMutableState<Boolean>
on every recomposition (in a SideEffect
). Would using a LaunchedEffect(value) { mutableState.value = value }
make any difference, given that the value only ever switches between simple true/false? Some more context in 🧵next.withCurrent {}
before the equality check comes through; and theres quite a bit of logic happening in there.
@Suppress("UNCHECKED_CAST")
override var value: T
get() = next.readable(this).value
set(value) = next.withCurrent {
if (!policy.equivalent(it.value, value)) {
next.overwritable(this, it) { this.value = value }
}
}
@PublishedApi
internal fun <T : StateRecord> current(r: T) =
Snapshot.current.let { snapshot ->
readable(r, snapshot.id, snapshot.invalid) ?: sync {
Snapshot.current.let { syncSnapshot ->
readable(r, syncSnapshot.id, syncSnapshot.invalid)
}
} ?: readError()
}
natario1
11/03/2023, 7:28 AMZoltan Demant
11/03/2023, 8:17 AMSideEffect docs say that you are not supposed to interact with compose-managed state in there.I wasnt aware of that, do you have the source for it? I get very broad search results as soon as SideEffect is included 😅
natario1
11/03/2023, 8:24 AMZoltan Demant
11/03/2023, 8:34 AMnatario1
11/03/2023, 8:47 AMLaunchedEffect
instead, keep SideEffect
for external stuff.Zoltan Demant
11/03/2023, 9:37 AMshikasd
11/03/2023, 3:53 PMSideEffect
and LaunchedEffect
are the same kinda thing, they just have different execution semantics. If you can use SideEffect
/ DisposableEffect
, they are much cheaper, as they don't create coroutine scope.
It is however a bit concerning that you are mutating a state in effects, this has potential of creating recomposition loops. Why do you need this?Zoltan Demant
11/04/2023, 6:42 AM