Classes

The following classes are available globally.

  • A Store is the core of the application. It is used to manage state and handle events sent to it.

    Generally an application will have one store and then use the scope function to create sub stores for different components of the app.

    See more

    Declaration

    Swift

    @MainActor
    public final class Store<State, Event, Environment>
  • A view model wraps a store and observes state changes that can be used within a view.

    extension RootScreen {
        struct ContentView: View {
            let store: Store
            @StateObject var viewModel: ViewModel<AppState, AppEvent>
    
            // MARK: Body
    
            var body: some View {
                VStack(alignment: .center) {
                    Text(verbatim: .init(self.viewModel.count))
                        .font(.largeTitle)
    
                    HStack {
                        Button("Decrement") {
                            self.viewModel.send(.decrement)
                        }
                        .buttonStyle(.bordered)
    
                        Button("Increment") {
                            self.viewModel.send(.increment)
                        }
                        .buttonStyle(.bordered)
    
                        Button("Delayed increment") {
                            self.viewModel.send(.incrementWithDelay)
                        }
                        .buttonStyle(.bordered)
                    }
                }
            }
        }
    }
    
    See more

    Declaration

    Swift

    @MainActor
    @dynamicMemberLookup
    public final class ViewModel<State, Event> : ObservableObject where State : Equatable