Skip to content

mori-atsushi/kredux

Folders and files

NameName
Last commit message
Last commit date
Nov 29, 2023
Sep 3, 2023
Jan 3, 2024
Sep 16, 2023
Sep 16, 2023
Sep 16, 2023
Sep 16, 2023
Aug 29, 2023
Sep 3, 2023
Sep 16, 2023
Sep 16, 2023
Sep 16, 2023
Sep 16, 2023
Sep 16, 2023
Oct 4, 2023
Sep 5, 2023
Sep 3, 2023
Sep 3, 2023

Repository files navigation

KRedux

KRedux is a simple implementation of Redux in Kotlin.

Setup

dependencies {
    implementation("com.moriatsushi.kredux:kredux-core:1.0.0-alpha01")
    // optional: If you want to use side effect.
    implementation("com.moriatsushi.kredux:kredux-side-effect:1.0.0-alpha01")
    // optional: If you want to use this with Jetpack Compose.
    implementation("com.moriatsushi.kredux:kredux-compose:1.0.0-alpha01")
}

Usage

Step 1. Define State and Action

data class CounterState(val count: Int = 0)

sealed class CounterAction {
    data object Increment : CounterAction()
    data object Decrement : CounterAction()
}

Step 2. Define Reducer

val counterReducer = Reducer(CounterState(0)) { acc, action: CounterAction ->
    when (action) {
        is CounterAction.Increment -> acc.copy(count = state.count + 1)
        is CounterAction.Decrement -> acc.copy(count = state.count - 1)
    }
}

Step 3. Create Store

val store = Store(counterReducer)

APIs

https://mori-atsushi.github.io/kredux/