svenjacobs
08/28/2019, 7:30 AMChannel
with Flow
in my Android application. But now I'm stuck in a conceptual thinking problem: Right now I use Channel
to handle UI events on Android views, for instance clicks inside a RecyclerView.Adapter
. I create an instance of Channel
in the view (or presenter, it doesn't matter) and pass it to the RecyclerView.Adapter
. Then inside the adapter I could just pass click events to the channel. But with Flow
, the flow needs to be created at the place where the data is emitted. However I don't want to have x flows in my Adapter for every view the adapter manages. Is Flow
even suited for UI events or are UI events classically hot streams? Am I just trying to apply Flow
where Channel
is the right choice after all?bdawg.io
08/28/2019, 7:36 AMsvenjacobs
08/28/2019, 7:37 AMdarkmoon_uk
08/28/2019, 7:37 AMFlow
isn't necessarily a replacement for Channel
- Channel
is appropriate for 'hot' events like live interactions with your UI.BehaviourSubject
- subscription to which offers an immediate 'last known' value (cold), followed by subsequent updates (hot).ConflatedBroadcastChannel
svenjacobs
08/28/2019, 7:40 AMConflatedBroadcastChannel
🙂 So basically channels are the right choice for hot UI eventsdarkmoon_uk
08/28/2019, 7:40 AMsvenjacobs
08/28/2019, 7:40 AMChannel
with Flow
for my API requestsdarkmoon_uk
08/28/2019, 7:41 AMasFlow
to gain the Flow-API benefits for any BroadcastChannel
.yshrsmz
08/28/2019, 8:17 AMelizarov
08/28/2019, 8:57 AMdarkmoon_uk
08/28/2019, 9:19 AMStateFlow
is most incisive, because:
- Data Flow implies data in an untyped, raw form, which this is (usually) not.
- Value Flow somewhat clashes by name with Kotlins val
, implying unchanging, or constant, which this is not.
- State Flow - as you said yourself, succinctly point to the fact there is an ever-present state of this thing, which can be accessed... but which flows, changes.svenjacobs
08/28/2019, 1:25 PMChannel
with Flow
for my API requests. Using Firebase Firestore here and want to listen for document updates. As of now I create a Channel
, then on the Firestore Query
I call `addSnapshotListener()`and inside the listener I call channel.offer()
when there are snapshots incoming. Also I call channel.invokeOnClose { registration.remove() }
where registration
is the ListenerRegistration
returned by addSnapshotListener
. How do I perform the last step with Flow
, ensuring that no listeners are leaked?Dominaezzz
08/28/2019, 1:28 PMcallbackFlow
.