mirror of
https://github.com/ivanvorobei/SwiftUI.git
synced 2026-01-15 21:53:29 +01:00
35 lines
747 B
Swift
Executable File
35 lines
747 B
Swift
Executable File
import SwiftUI
|
|
|
|
struct CounterView : View {
|
|
enum Action {
|
|
case increment
|
|
case decrement
|
|
}
|
|
|
|
@State var store = Store<Int, Action>(initial: 0) { count, action in
|
|
switch action {
|
|
case .increment:
|
|
return count + 1
|
|
|
|
case .decrement:
|
|
return max(0, count - 1)
|
|
}
|
|
}
|
|
|
|
var body: some View {
|
|
VStack {
|
|
Text("\(store.state)")
|
|
|
|
HStack {
|
|
Button(action: { self.store.dispatch(action: .decrement) }) {
|
|
Text("Decrement")
|
|
}
|
|
|
|
Button(action: { self.store.dispatch(action: .increment) }) {
|
|
Text("Increment")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|