cl3m / kmp-redux

Basic redux setup for kotlin multiplatform with JetPack Compose and SwiftUI

Repository from Github https://github.comcl3m/kmp-reduxRepository from Github https://github.comcl3m/kmp-redux

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

About

Basic redux setup for kotlin multiplatform with JetPack Compose and SwiftUI

License:Apache License 2.0


Languages

Language:Kotlin 76.5%Language:Swift 19.0%Language:Ruby 4.5%