Redux-kt is a simple Redux-like implementation for kotlin. This product is very inspired by ReSwift.
This section explains a few steps to get started with redux-kt.
Redux-kt is distributed with jitpack.io so you can use it with build systems that can resolve dependencies with maven repositories.
With gradle project, follow steps below to install redux-kt as a dependency.
Open build.gradle
of the target project and add repository setting.
buildscript {
repositories {
maven { url 'https://jitpack.io' }
}
}
Open build.gradle
of the target project and insert redux-kt as a dependency of the target.
dependencies {
compile 'com.github.rettyeng.redux-kt:redux-kt-core:0.0.2'
}
With mvn, follow steps below to install redux-kt as a dependency.
Open pom.xml
of the target project and add repository
tag.
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add redux-kt as a dependency of the project.
<dependencies>
<dependency>
<groupId>com.github.rettyeng.redux-kt</groupId>
<artifactId>redux-kt-core</artifactId>
<version>0.0.2</version>
</dependency>
</dependencies>
A minimal example is below. If you want more examples, you can find a sample Android app project in this repository. See also Sample apps.
data class ApplicationState(val text: String = ""): StateType
data class PostTextAction(val text: String): Action
val reducer: Reducer<ApplicationState> = { action, state ->
when(action) {
is PostTextAction -> state.copy(text = action.text)
else -> state.copy()
}
}
val loggingMiddleware: Middleware<ApplicationState> = {
{ dispatch ->
{ action ->
Log.d("Middleware", "dispatching action $action")
dispatch(action)
}
}
}
val store = Store<ApplicationState>(ApplicationState(),
reducer,
listOf(loggingMiddleware))
store.subscribe { old, new ->
println("New state is $new")
}
store.dispatch(PostTextAction("foobar"))
README of the sample.
Feel free to report bugs, to create issues, or to create PRs.
Install maven and run following command.
mvn package
Import jar into your project as a library or install a snapshot to local maven and use it.
Use maven-plugin to install.
mvn install
Use snapshot as a dependency.
With gradle, repository settings is needed to use maven local cache.
buildscript {
repositories {
mavenLocal()
}
}
dependencies {
compile 'com.github.rettyeng.redux-kt:redux-kt-core:0.0.2-SNAPSHOT'
}
<dependencies>
<dependency>
<groupId>com.github.rettyeng.redux-kt</groupId>
<artifactId>redux-kt-core</artifactId>
<version>0.0.2-SNAPSHOT</version>
</dependency>
</dependencies>