Skip to content

Files

Latest commit

4abbdb5 · Jun 28, 2020

History

History
84 lines (67 loc) · 2.92 KB

README.md

File metadata and controls

84 lines (67 loc) · 2.92 KB

Presenter Middleware

badge badge badge badge badge badge badge badge

Write concise multiplatform presenter functions with presenter-middleware:

interface StartView : GameBaseView {
    fun showLoading()
    fun hideLoading()
    fun showError(msg: String)

    override fun presenter(): Presenter<View, AppState> = startPresenter
}

val startPresenter = presenter<StartView> {
    {
        select { state.isLoadingItems } then {
            if (state.isLoadingItems) {
                showLoading()
            } else {
                hideLoading()
            }
        }

        select { state.errorLoadingItems } then { showError(state.errorMsg) }
    }
}

Presenter-middleware handles wiring this up to your view and store subscriptions. Just implement the interface on Android and iOS and dispatch lifecycle events. See the ReadingList sample app or the Name Game Sample App for example usage.

How to add to project:

Artifacts are hosted on maven central. For multiplatform, add the following to your shared module:

kotlin {
  sourceSets {
        commonMain { //   <---  name may vary on your project
            dependencies {
                implementation "org.reduxkotlin:presenter-middleware:0.2.8"
            }
        }
 }

Add the presetner store-enhancer:

  val appStore = createStore(reducer, AppState.INITIAL_STATE,
                    compose(listOf(presenterEnhancer(uiContext),
                            applyMiddleware(createThunkMiddleware())

For JVM only:

  implementation "org.reduxkotlin:presenter-middleware-jvm:0.2.8"