mirror of
https://github.com/ivanvorobei/SwiftUI.git
synced 2026-03-30 22:22:11 +02:00
Add Flux
This commit is contained in:
34
Examples/Flux/SwiftUI-Flux/CounterView.swift
Executable file
34
Examples/Flux/SwiftUI-Flux/CounterView.swift
Executable file
@@ -0,0 +1,34 @@
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user