Skip to content

reduxkotlin/presenter-middleware

Repository files navigation

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"

About

Presenter middleware for updating views based on selectors & reselect for Redux-Kotlin. Mulitiplatform supported.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages