This module contains UiStore that provides functionality:
- Convert models to Ui Models
- Cache ui effects when there is no subscribers and emit cached effects with a first subscription. It can be disabled using
parameter
cacheUiEffects = false
.
You can use UiStoreBuilder and function uiBuilder
for convenient usage
without declaring all 6 generics. [UiStoreBuilder] also provides some build in functions, and you can easily extend it using extension fun.
Take a look to the sample.feature.ui for detailed examples of usage.
If your UiMsg and UiEff are subclasses of Msg and Eff, you can use following code for simple mapping only UiState
val store: Store<Msg, State, Eff> = ...
val uiStore = store.uiBuilder().using<Msg.Ext, UiState, Eff.Ext> { state ->
UiState(
state.itemsIds.map { resources.getString(R.string.item_title, it) }
)
}
Otherwise, you can provide your own mappers for UiMsg -> Msg and for Eff -> UiEff
store.uiBuilder().using<Msg.Ext, UiState, Eff.Ext>(
uiMsgToMsgConverter = { it },
uiStateConverter = { state ->
UiState(
state.itemsIds.map { resources.getString(R.string.item_title, it) }
)
},
uiEffConverter = { eff ->
eff as? Eff.Ext
}
)