-
Notifications
You must be signed in to change notification settings - Fork 96
Open
Labels
Description
I'm trying to migrate
val data = snapshotFlow { buildFromState() }.debounce(1.seconds)
...
data.collectAsState(null)
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
val debouncedFlow = snapshotFlow { buildFromState() }.debounce(1.seconds)
val state = scope.launchMolecule {
debouncedFlow.collectAsState(buildFromState()).value
}
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 calling buildFromState()
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.