Skip to content

Latest commit

 

History

History
100 lines (74 loc) · 1.78 KB

README.md

File metadata and controls

100 lines (74 loc) · 1.78 KB

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())
        }
    }
}