Closed svenjacobs closed 4 years ago
Hi. Thanks for the feature request!
Can you give me a couple of use cases i.e. what would you do with a Flow
of LifecycleEvents?
Can you give me a couple of use cases i.e. what would you do with a Flow of LifecycleEvents?
I'm currently implementing the Model-View-Intent pattern in an Android application utilizing coroutines and Flow. My idea is that any kind of event, be it a click event or a lifecycle event, is represented through Flows. So the only communication between the view and the "presenter" is through Flow.
interface SomeView {
val onCreateEvents: Flow<Unit>
val onButtonClickEvents: Flow<Unit>
}
then somewhere else
val onCreateFlow = view.onCreateEvents
.onEach { // Do something with this event }
val onButtonClickFlow = view.onButtonClickEvents
.onEach { // Do something with this event }
flowOf(
onCreateFlow,
onButtonClickFlow
).flattenMerge().launchIn(someScope)
The example is greatly simplified but I hope you get what I mean.
val onCreateFlow = view.onCreateEvents .onEach { // Do something with this event }
What would you put in the
onEach
block here? πIs it some kind of side-effect or mapping to some sealedEvent
type that the presenter / view model takes as input?
I'm asking as I can't quite wrap my head around how a stream of lifecycle events can help in a MVI setup. Ideally the presenter / viewmodel should not be aware of the Android Lifecycle. The only use case I can think of where monitoring Lifecycle events is useful (other than subscribing and unsubscribing event listeners) is analytics reporting. Am I missing something?
Anyway this library probably shouldn't be too opinionated on how it's used. So I'll work on this next week.
What would you put in the onEach block here? πIs it some kind of side-effect or mapping to some sealed Event type that the presenter / view model takes as input?
As I said my example is simplified π What I do is (instead of onEach
) map the incoming events into changes of a State
data class. This State
represents the UI state. For the onCreate
event for example I would start loading some data and put it in the state.
Got you π
Nice π I'm looking forward to your implementation!
Added new LifecycleEventFlow. This will be in the next release.
Nice, thanks! π
0.9.0
is out. Should be available on Maven Central soon.
Thanks for this useful library π
I suggest adding a new artifact
flowbinding-lifecycle
which supportsFlow
of Lifecycle events. Here's a proposal of how this could look like:Thank you!