@@ -13,20 +13,14 @@ struct BlocContentView: View {
13
13
var body : some View {
14
14
NavigationView {
15
15
BlocView ( builder: { ( bloc) in
16
- VStack {
17
- if bloc. state. count > 5 {
18
- LimitView ( )
19
- } else {
20
- OperationView ( )
16
+ CounterView ( )
17
+ . alert ( isPresented: bloc. shouldShowAlertBinding) {
18
+ Alert (
19
+ title: Text ( " Hi " ) ,
20
+ message: Text ( " Message " ) ,
21
+ dismissButton: . cancel { }
22
+ )
21
23
}
22
- }
23
- . alert ( isPresented: bloc. shouldShowAlertBinding) {
24
- Alert (
25
- title: Text ( " Hi " ) ,
26
- message: Text ( " Message " ) ,
27
- dismissButton: . cancel { }
28
- )
29
- }
30
24
} , action: { ( bloc) in
31
25
if bloc. state. count < - 5 {
32
26
for _ in 0 ..< 6 {
@@ -39,19 +33,28 @@ struct BlocContentView: View {
39
33
}
40
34
}
41
35
36
+ struct CounterView : View {
37
+ @EnvironmentObject var bloc : CounterBloc
38
+
39
+ var body : some View {
40
+ if bloc. state. count > 5 {
41
+ LimitView ( )
42
+ } else {
43
+ OperationView ( )
44
+ }
45
+ }
46
+ }
47
+
42
48
struct LimitView : View {
43
49
@EnvironmentObject var bloc : CounterBloc
44
50
45
51
var body : some View {
46
52
VStack {
47
53
Text ( " Hooora " )
48
54
Button ( action: {
49
- self . bloc. add ( event: . decrement)
50
- self . bloc. add ( event: . decrement)
51
- self . bloc. add ( event: . decrement)
52
- self . bloc. add ( event: . decrement)
53
- self . bloc. add ( event: . decrement)
54
- self . bloc. add ( event: . decrement)
55
+ for _ in 0 ..< 6 {
56
+ bloc. add ( event: . decrement)
57
+ }
55
58
} , label: {
56
59
Text ( " Reset " )
57
60
} )
@@ -65,12 +68,12 @@ struct OperationView: View {
65
68
var body : some View {
66
69
VStack {
67
70
Button ( action: {
68
- self . bloc. add ( event: . increment)
71
+ bloc. add ( event: . increment)
69
72
} , label: {
70
73
Text ( " Send Increment event " )
71
74
} )
72
75
Button ( action: {
73
- self . bloc. add ( event: . decrement)
76
+ bloc. add ( event: . decrement)
74
77
} , label: {
75
78
Text ( " Send Decrement event " )
76
79
} )
0 commit comments