Skip to content
Redux implementation for Kotlin (supports multiplatform JVM, native, JS, WASM)
Kotlin JavaScript CSS
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci Merge branch 'task/website-CD' of github.com:reduxkotlin/redux-kotlin… Sep 28, 2019
buildSrc update to kotlin 1.3.60 (#29) Nov 30, 2019
examples enforce same thread on getState() (#34) Dec 16, 2019
gradle
lib update docs to use 0.3.1 (#36) Dec 19, 2019
website update docs to use 0.3.1 (#36) Dec 19, 2019
.gitignore
CHANGELOG.md update docs to use 0.3.1 (#36) Dec 19, 2019
LICENSE
README.md
build.gradle update to kotlin 1.3.60 (#29) Nov 30, 2019
gradle.properties initial commit. Redux without tests May 24, 2019
gradlew updated to gradle 5.6-rc1 Aug 5, 2019
gradlew.bat updated to gradle 5.6-rc1 Aug 5, 2019
settings.gradle

README.md

Redux-Kotlin

CircleCI

badge badge badge badge badge badge badge badge

A redux standard for Kotlin that supports multiplatform projects

Misson Statement

Provide a standard redux implementation for Kotlin. In doing so will foster a ecosystem of middleware, store enhancers, & dev tools. These core values will guide descisions for the project:

  • core redux-kotlin will be a minimal implementation that other libraries can build upon
  • modular development (follow example of https://github.com/reduxjs)
  • support for all platforms supported by Kotlin multiplatform (JVM, iOS, Native, JS, WASM)
  • developed in open and enable discussion for all interested parties via open channels (slack, github, etc. TBD)
  • not owned by a individual or company

Redux in Kotlin, and in mobile in particular, may differ a bit from javascript. Many have found the basic pattern useful on Android & iOS leading to tens of opensource redux libraries in Kotlin, Java, and Swift, yet an ecosystem has yet to emerge. A port of javascript redux is a good starting point for creating a standard and will aid in cross-pollination of middleware, store enhancers, & dev tools from the javascript world.

Redux has proven helpful for state managment in mobile. A multiplatform Kotlin implementation & ecosystem will increase developer productivity and code reuse across platforms.

Droidcon NYC Slides Video TBA

*** PLEASE FILL OUT THE Redux on Mobile Survey ***

How to add to project:

Artifacts are hosted on maven central. They are published with gradle metadata, so you may need to enable with enableFeaturePreview("GRADLE_METADATA") in your settings.gradle file. For multiplatform, add the following to your shared module:

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

For JVM only:

  implementation "org.reduxkotlin:redux-kotlin-jvm:0.3.1"

Usage is very similar to JS Redux and those docs will be useful https://redux.js.org/. These docs are not an intro to Redux, and just documentation on Kotlin specific bits. For more info on Redux in general, check out https://redux.js.org/.

Create an AppState class

  data class AppState(val user: User, val feed: List<Feed>)

Create Reducers:

  val reducer: Reducer<AppState> =  { state, action ->
    when (action) {
        is UserLoggedInAction -> state.copy(user = action.user)
        ...
    }
  }

Create Middleware: There are a few ways to create middleware:

Using a curried function stored in a val/var:

  val loggingMiddleware: Middleware = 
          { store ->
              { next ->
                  { action ->
                        //log here
                        next(action)
                   }
               }
            }

Using a function:

  fun loggingMiddleware(store: Store) = { next: Dispatcher -> 
              { action: Any -> 
                     //log here
                     next(action)
               }

Using the convinence helper function middleware:

   val loggingMiddleware = middleware { store, next, action -> 
          //log here
          next(action)
          }

Create a store

  val store = createStore(reducer, AppState(user, listOf()), applyMiddleware(loggingMiddleware))

You then will have access to dispatch and subscribe functions from the store.

Communication

Want to give feedback, contribute, or ask questions?

#redux slack channel in kotlinlang

Trello boards - https://trello.com/reduxkotlinorg

Or create an issue on github.

You can’t perform that action at this time.