android / architecture-samples

A collection of samples to discuss and showcase different architectural tools and patterns for Android apps.
Apache License 2.0
44.32k stars 11.62k forks source link

MVVM+ branch #875

Closed tunjid closed 1 year ago

tunjid commented 2 years ago

Produces state by using a StateProducer that merges flows that carry functions that lazily modify the state.

This avoids the issues that can arise when combining flows:

This change has the interesting side effect of only being able to push state changes only if there is an observer of UI state. If there is no observer of state, all pending pushes will suspend until an observer is present.

It also means and coroutines launched have to honor the SharingStarted passed to the StateProducer. This means both Flows and suspend functions in ViewModels only run as specified by WhileUiSubscribed which is SharingStarted.WhileSubscribed(5_000).

It also lets users just setState.