Debouncing state emissions
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 2.2k
- Forks
- 116
- Avg merge
- 1h 36m
- Merged PRs (30d)
- 8
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the Molecule recomposition behavior around launchMolecule and compare it with the snapshotFlow/debounce and collectAsState examples in the issue. Determine whether controlled or throttled recomposition is feasible without redundant buildFromState() calls; done requires an agreed design and corresponding behavior tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- mobile-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100