leandro
01/07/2021, 3:29 PMSendChannel
backed by a RENDEZVOUS
implementation, but wondering if MutableSharedFlow
(with replay=0
) would be better (i assume due to less overhead?!)Rob
01/07/2021, 3:31 PMMutableSharedFlow(extraBufferCapacity = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST)
and .tryEmit()
to replace PublishSubjects for this use case.leandro
01/07/2021, 3:35 PMextraBufferCapacity
but the values you’re initializing the Flow makes total senseRob
01/07/2021, 3:49 PMtryEmit()
when not in a suspend function. The event gets buffered until the suspended coroutine resumes.Adam Powell
01/07/2021, 3:55 PMRob
01/07/2021, 3:59 PMAdam Powell
01/07/2021, 4:06 PMRob
01/07/2021, 4:09 PMAdam Powell
01/07/2021, 4:20 PMRob
01/07/2021, 4:32 PMleandro
01/07/2021, 7:40 PMcollect
the primitive (either my current implementation -- a channel -- or a more optimised entity e.g. MutableSharedFlow
), and expose this primitive to 0-to-many "viewtrees" (not exactly, but imagine I had a ViewModel
by activityViewModels()
and had different fragments sending UI events (e.g. button clicks) to the centralised processor/presenter).Rob
01/07/2021, 7:55 PMAdam Powell
01/07/2021, 7:59 PMleandro
01/07/2021, 8:52 PMclass Presenter {
val events: ReceiveChannel<Event>
suspend fun start() {
events.consumeEach {
//
}
}
}
where each fragment would be like:
class MyFragment : Fragment {
@Inject presenter: Presenter
fun onCreatedView() {
view.findViewById(R.id.plus).setOnClickLister {
presenter.events.offer(Event.OnPlusClick)
}
view.findViewById(R.id.minus).setOnClickLister {
presenter.events.offer(Event.OnMinusClick)
}
}
}
But oftentimes it’s a 1:1Rob
01/07/2021, 9:07 PM