Closed 6iovan closed 5 years ago
You must call setState
from the ViewModel. The data class should be copied and a new version made.
see the wiki https://github.com/airbnb/MvRx/wiki#core-concepts https://github.com/airbnb/MvRx/wiki#updating-state
@elihart
I did call setState
or execute
from the ViewModel, but it’s not work when I use epoxy + paging support.
Thank you for your answer!~
implementation 'com.airbnb.android:mvrx:0.7.2'
implementation 'com.airbnb.android:epoxy:2.19.0'
implementation 'com.airbnb.android:epoxy-paging:2.19.0'
data class LandMainState(
val historyItemData: Async<List<LandMainAlbum>> = Uninitialized,
...
val albumAllItemData: Async<PagedList<Pair<Album, Album>>> = Uninitialized
) : MvRxState
class LandMainViewModel(state: LandMainState) : MvRxViewModel<LandMainState>(state) {
fun loadHistoryCards() {
LandMainLocalDataSource.getHistoryCars()
.subscribeOn(Schedulers.io())
.execute { copy(historyItemData = it) }
}
}
viewModel.asyncSubscribe(this, LandMainViewModel::albumAllItemData) {
rxController.submitList(it)
}
I call submitList
in the Activity#onCreate(), then i want to call loadHistoryCards
in the Activity#onResume(). Crash happened..
I got it, PagedList
cannot be used in State.
Hello! :smile:
I want to change the view multiple times, but "XXX was mutated. State classes should be immutable."
thank you.