Skip to content

Latest commit

 

History

History
44 lines (34 loc) · 1.67 KB

README.md

File metadata and controls

44 lines (34 loc) · 1.67 KB

UI Adapter

Maven Central Version

This module contains UiStore that provides functionality:

  1. Convert models to Ui Models
  2. 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.

Sample

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
    }
)