Open TheKeeperOfPie opened 7 months ago
@Composable
fun <T> debounce(value: T, duration: Duration): T {
// ????
}
This can't be implemented on a StateFlow
, but it should be implementable in compose
I think that perhaps we want to consider accepting a frame clock even when using immediate mode. This would allow you to use an at-most-once-a-second frame clock either directly, or with the immediate mode. It would apply the back pressure to the recomposition rather than allowing it to run unbounded simply to discard its results.
I think that perhaps we want to consider accepting a frame clock even when using immediate mode.
I would think this would be equivalent to using the frame clock directly. What advantage does this give us over providing some utility code to create frame clocks from Flow<Unit>
, or something similar?
I was thinking that there was some advantage to still using the immediate mode such as immediately running if the period had already expired, but you're right that's just clock implementation details.
I'm trying to migrate
to remove the view side default
null
value.But there's no easy way to debounce in Molecule. I think the closest you can get would be
but this moves from Compose (the actual state) -> Flow (
snapshotFlow
) -> Molecule -> Compose (collectAsState
) -> Compose UI, which is very inefficient compared to reading the state directly inside Molecule. It also requires callingbuildFromState()
redundantly.If there was a way to control/throttle the recomposition timing in Molecule, then I could try and make it only recompose every second or when the debounce concluded.