Skip to content

swiftty/reactorium

Repository files navigation

test

REACTORIUM

Highly inspired by The Composable Architecture (TCA).



# CONCEPT

A Lightwieght TCA for SwiftUI friendly.


# INSTALLATION

Under Development

dependencies: [
    .package(url: "https://github.com/swiftty/reactorium", from: "0.0.2")
]

# USAGE

  • define Reducer
import SwiftUI
import Reactorium

struct Counter: Reducer {
    struct State {
        var count = 0
    }

    enum Action {
        case incr
        case decr
    }

    func reduce(into state: inout State, action: Action, dependency: ()) -> Effect<Action> {
        switch action {
        case .incr:
            state.count += 1
            return nil

        case .decr:
            state.count -= 1
            return nil
        }
    }
}

struct CounterView: View {
    @EnvironmentObject var store: StoreOf<Counter>

    var body: some View {
        VStack {
            Text("\(store.state.count)")

            HStack {
                Button { store.send(.decr) } label: {
                    Image(systemName: "minus")
                        .padding()
                }

                Button { store.send(.incr) } label: {
                    Image(systemName: "plus")
                        .padding()
                }
            }
        }
    }
}

  • inject using View.store modifier
import SwiftUI
import Reactorium

struct MyApp: App {
    var body: some Scene {
        WindowScene {
            CounterView()
                .store(initialState: .init(), reducer: Counter())
        }
    }
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages