Orhan Tozan
03/18/2020, 10:16 PMonUserSelect(userId: Int)
I want it to offer an event to a broadcastchannel named userSelectEvents: BroadCastChannel<UserSelectEvent>
. The flow selectedUsers
should depend on this, so I'm probably looking to some kind of building a reducer. This is my idea, is it good?Zach Klippenstein (he/him) [MOD]
03/18/2020, 11:08 PMOrhan Tozan
03/18/2020, 11:35 PMclass ViewModel {
val selectedUserIds: Flow<List<Int>> = ...
fun onUserSelect(userId: Int) {
...
}
}
How would you implement this?Zach Klippenstein (he/him) [MOD]
03/18/2020, 11:44 PMonUserSelect
and the lists emitted from selectedUserIds
? Do newly-selected IDs just get appended to the list?Orhan Tozan
03/18/2020, 11:46 PMZach Klippenstein (he/him) [MOD]
03/18/2020, 11:57 PMConflatedBroadcastChannel
, since it lets you access the current value (value
property). Then you can just get the current list, append, and offer the new list.Orhan Tozan
03/19/2020, 12:02 AMZach Klippenstein (he/him) [MOD]
03/19/2020, 12:30 AMuserEventsToSelectedUserIds
do? how are you accumulating the list of user IDs?Orhan Tozan
03/19/2020, 2:29 PMOrhan Tozan
03/19/2020, 2:31 PMonSaveButtonClick()
method that sends a network call with the selectedUserIds
. Should I get it's value by using the .value
of the ConflatedBroadcastChannel
or should I launch a coroutine and call .collect
on the Flow
?Zach Klippenstein (he/him) [MOD]
03/19/2020, 2:53 PMselectedUserIds.first()
.Orhan Tozan
03/19/2020, 2:54 PMOrhan Tozan
03/19/2020, 2:54 PMprivate val _selectedUserIds = ConflatedBroadcastChannel<List<Int>>(emptyList())
private val selectedUserIds: Flow<List<Int>> = _selectedUserIds.asFlow()
A onSaveButtonClick()
method should send a network call with the value of selectedUserIds
Should I get it's value by using the .value
of the ConflatedBroadcastChannel
or should I launch a coroutine and call .collect()
on the Flow
? What's the difference?Orhan Tozan
03/19/2020, 2:55 PMOrhan Tozan
03/19/2020, 2:55 PM.last()
, since it represents the last emitted value?Orhan Tozan
03/19/2020, 2:56 PM/**
* The terminal operator that returns the first element emitted by the flow and then cancels flow's collection.
* Throws [NoSuchElementException] if the flow was empty.
*/
public suspend fun <T> Flow<T>.first(): T {
Orhan Tozan
03/19/2020, 2:56 PM