Protocols
The following protocols are available globally.
-
A protocol to help guide structuring a SwiftUI view to use RedUx.
The use of this protocol isn’t required in order to use RedUx. It can be used as a guide on how to setup RedUx.
An example of this may look like:
See moreimport RedUx import SwiftUI struct RootScreen: View, RedUxable { typealias LocalState = AppState typealias LocalEvent = AppEvent typealias LocalEnvironment = AppEnvironment let store: LocalStore @StateObject var viewModel: LocalViewModel // MARK: Initialization init(store: LocalStore, viewModel: LocalViewModel) { self.store = store self._viewModel = .init(wrappedValue: viewModel) } // 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) } } } } // MARK: Preview struct RootScreen_Previews: PreviewProvider { static var previews: some View { RootScreen.mock( state: .init( count: 0 ), environment: .mock ) } }
Declaration
Swift
@MainActor public protocol RedUxable