Dominaezzz
02/25/2021, 10:50 PMproduceState
should forget the initial value if any of the input keys change.collectAsState
for `StateFlow`s.Leland Richardson [G]
02/25/2021, 11:20 PMZach Klippenstein (he/him) [MOD]
02/26/2021, 12:13 AMLeland Richardson [G]
02/26/2021, 12:55 AMZach Klippenstein (he/him) [MOD]
02/26/2021, 12:58 AMcollectAsState
case where the flow itself is the key, and the initial value is derived from the flow, then it makes sense. But it’s possible there could be a case where the initial value is not derived from the keys, in which case it might be weird to change the value back to the original initial value instead of just leaving the last state there. I’m not sure which case is more general.Leland Richardson [G]
02/26/2021, 1:09 AMSean McQuillan [G]
02/26/2021, 1:14 AMAdam Powell
02/26/2021, 2:39 AMproduceState
and StateFlow.collectAsState
separately. Snapping to the current StateFlow.value
for a new StateFlow seems more compelling than changing produceState
key(...) {}
- doing the reverse if produceState
were changed would be more cumbersomeDominaezzz
02/26/2021, 9:39 AMZach Klippenstein (he/him) [MOD]
02/26/2021, 9:15 PMSean McQuillan [G]
02/26/2021, 9:29 PMvalue = Initial
as the first line of the producer lambda, as it will restart when the keys changeAdam Powell
02/26/2021, 9:59 PMproduceState
from the API entirely and observeDominaezzz
03/07/2021, 3:34 PMIt doesn't make the first recomposition with the new key thoughWhat does this mean? If you set a mutable state during (re?)composition, do you still see the old value until the next recomposition?
Adam Powell
03/07/2021, 3:46 PMproduceState {}
doesn't run during composition, it runs after the composition is applied. The rest of that same composition pass will have seen the previous value. The change will schedule another recomposition for a future frame, not affect the recomposition that already happened.Dominaezzz
03/07/2021, 3:50 PMvalue = Initial
as Sean suggested, count as side effect? Specifically, the kind of side effect we're supposed to avoid in composable functions.Adam Powell
03/07/2021, 4:00 PMvar counter = remember { mutableStateOf(0) }
Text("Count: $counter")
SomeComposable { // @Composable lambda parameter
counter++ // backwards write!
Text("New count: $counter")
}
then we're left with a host of bad options for interpreting what you meant in any sort of declarative wayDominaezzz
03/07/2021, 4:06 PMAdam Powell
06/05/2021, 2:42 PMproduceState
as @Experimental
for 1.0Dominaezzz
06/05/2021, 2:45 PM@Experimental
would be ideal I think. At least it can be changed later if need be.Adam Powell
06/07/2021, 9:23 PMDominaezzz
06/08/2021, 7:38 AMproduceState
as is makes sense to me. Thinking of it as a switchMap
or transformLatest
did the trick.collectAsState
? It's continuity is handled by the upstream flow, at least for StateFlow
. Plain Flow
is somewhat debatable but I'm not fussed about it.Adam Powell
06/08/2021, 1:37 PMZach Klippenstein (he/him) [MOD]
11/08/2021, 5:13 PMcollectAsState
, or at least the overload with a StateFlow
receiver, be to immediately return the new flow’s initial value when the flow changes? It is very counter-intuitive for it to do otherwise, so if not, why not?produceState
and it makes sense to leave that as-is.Dominaezzz
11/08/2021, 5:24 PM