https://kotlinlang.org logo
#coroutines
Title
# coroutines
d

dave08

05/21/2020, 8:04 AM
StateFlow<Unit?>
can't be used to represent clicks since it's conflated right (unless a new object is created for each emission...)? But
SharedFlow
will?
Actually, it might be possible to do:
Copy code
_onClick.value = Unit
_onClick.value = null
for each click, and then use
filterNotNull()
on the listener's flow... 🙈
l

louiscad

05/21/2020, 10:05 AM
Why not just use a
Flow
, or an
awaitOneClick()
function that disables the button when clicked?
d

dave08

05/21/2020, 10:08 AM
You're right in that case... but my actual case is returning a no-param "command" from the viewModel to the view where I need something I can set like a Subject, not just a Flow...
So I don't really want the conflated behavior to work here...
s

streetsofboston

05/21/2020, 12:15 PM
A click is an event, it represents a moment in time that something happens, not a persistent state. Use another type of flow. We created an
EventFlow
, extending
Flow
, for being able to share events, backed by a BroadcastChannel . We use this one mostly for navigation events emitted by the ViewModel
☝️ 1
👍🏼 1
d

dave08

05/21/2020, 12:23 PM
EventFlow
is not going to be covered by
SharedFlow
? Also, my little hack (null, Unit, null, Unit) wouldn't be more efficient than a
BroadcastChannel
implementation?
s

streetsofboston

05/21/2020, 12:37 PM
I have to closely look at the upcoming SharedFlow again. It may indeed handle the use-cases of the EventFlow