Files
SwiftUI/Examples/Flux/SwiftUI-Flux/CounterView.swift
Ivan Vorobei 6d351cf167 Add Flux
2019-06-06 22:31:08 +03:00

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