Skip to content

cl3m/kmp-redux

Repository files navigation

Kotlin Multiplatform

KMP Redux

Basic redux setup for kotlin multiplatform with JetPack Compose and SwiftUI. AppStore can be derived into sub store.

Libraries

Redux Usage

CounterStore usage on Jetpack Compose

@Composable
fun CounterView() {
    val state by CounterStore.current.state.collectAsState()
    val dispatch = CounterStore.current.dispatch

    Column(
        modifier = Modifier.fillMaxSize(),
        horizontalAlignment = Alignment.CenterHorizontally,
        verticalArrangement = Arrangement.spacedBy(20.dp, Alignment.CenterVertically)
    ) {
        Text(text = "$state")
        Row(horizontalArrangement = Arrangement.spacedBy(50.dp)) {
            Button(onClick = {
                dispatch(CounterAction.Increment)
            }) {
                Text(text = "+")
            }
            Button(onClick = {
                dispatch(CounterAction.Decrement)
            }) {
                Text(text = "-")
            }
        }
    }
}

CounterStore usage on SwiftUI

struct CounterView: View {
    @EnvironmentObject private var store: CounterStore

    var body: some View {
        return VStack(spacing: 20) {
            Text("\(store.state)")
            HStack(spacing: 50) {
                Button("+") {
                    store.dispatch(.increment)
                }
                Button("-") {
                    store.dispatch(.decrement)
                }
            }
        }
    }
}

Inspirations

Releases

No releases published

Packages

No packages published