zain
06/04/2021, 3:13 PMval players: SharedFlow<List<Player>> = MutableSharedFlow(,Player("Messi"), Player("Ronaldo"))
Is it possible to collect the changes of a list of object if one item is changed or updated?Charlie Christensen
06/04/2021, 3:16 PMMutableSharedFlow(listOf(Player("Messi"), Player("Ronaldo")))
To update it you have to pass a new list to the shared flowzain
06/04/2021, 3:18 PMInt
as it is expecting
public fun <T> MutableSharedFlow(
replay: Int = 0,
extraBufferCapacity: Int = 0,
onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND
): MutableSharedFlow<T>
Charlie Christensen
06/04/2021, 3:20 PMCharlie Christensen
06/04/2021, 3:20 PMzain
06/04/2021, 3:24 PMzain
06/04/2021, 3:31 PMzain
06/04/2021, 3:32 PMval players: Flow<List<Player>> = flow { listOf(Player("Messi"), Player("Ronaldo")) }.shareIn(
viewModelScope,
replay = 1,
started = SharingStarted.WhileSubscribed()
)
zain
06/04/2021, 3:32 PMclass NewsRemoteDataSource(...,
private val externalScope: CoroutineScope,
) {
val latestNews: Flow<List<ArticleHeadline>> = flow {
...
}.shareIn(
externalScope,
replay = 1,
started = SharingStarted.WhileSubscribed()
)
}
zain
06/04/2021, 3:33 PMCharlie Christensen
06/04/2021, 3:35 PMval players: Flow<List<Player>> = flow {
emit(listOf(Player("Messi"), Player("Ronaldo")))
}.shareIn(
viewModelScope,
replay = 1,
started = SharingStarted.WhileSubscribed()
)
Charlie Christensen
06/04/2021, 3:35 PMemit
itzain
06/04/2021, 3:55 PM