You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a potential feature request as it is uncertain whether this functionality currently exists with Flow.
Expected
Initialize a Kotlin Coroutine Flow and modify its' value after the Flow's creation.
The desired functionality is similar to MutableLiveData's setValue which allows data to be added to an existing MutableLiveData object.
In the example below setValue is called on the _feed MutableLiveData value in FeedViewModel.kt in order to update the value.
This works as expected, emitting the values in FeedFragment.kt
FeedViewState.kt
data class_FeedViewState(
val_feed:MutableLiveData<List<Tweet>> = MutableLiveData()
)
data classFeedViewState(privateval_feedViewState:_FeedViewState) {
val feed:LiveData<List<Tweet>> =_feedViewState._feed
}
In order to implement the same pattern using Kotlin Coroutines the LiveData in the FeedViewState.kt is replaced with Flow. In FeedViewModel.kt the desired result is to add data to the _feed Flow value. The attempted solutions have been applying map, and emit inside of transform and onCompletion to the _feed Flow value.
However, this solution does not emit the desired values from the Flow value in FeedFragment.kt.
FeedViewState.kt
data class_FeedViewState(
val_feed:Flow<List<Tweet>> = flow { }
)
data classFeedViewState(privateval_feedViewState:_FeedViewState) {
@ExperimentalCoroutinesApi
val feed:Flow<List<Tweet>> =_feedViewState._feed }
}
This is a potential feature request as it is uncertain whether this functionality currently exists with Flow.
Expected
Initialize a Kotlin Coroutine Flow and modify its' value after the Flow's creation.
The desired functionality is similar to MutableLiveData's
setValue
which allows data to be added to an existing MutableLiveData object.In the example below
setValue
is called on the_feed
MutableLiveData value in FeedViewModel.kt in order to update the value.This works as expected, emitting the values in FeedFragment.kt
FeedViewState.kt
FeedViewModel.kt
FeedFragment.kt
Observed
In order to implement the same pattern using Kotlin Coroutines the LiveData in the FeedViewState.kt is replaced with Flow. In FeedViewModel.kt the desired result is to add data to the
_feed
Flow value. The attempted solutions have been applyingmap
, andemit
inside oftransform
andonCompletion
to the_feed
Flow value.However, this solution does not emit the desired values from the Flow value in FeedFragment.kt.
FeedViewState.kt
FeedViewModel.kt
FeedFragment.kt
The text was updated successfully, but these errors were encountered: