@@ -15,17 +15,17 @@ extension CounterApp {
15
15
extension CounterApp . System {
16
16
static let counter = System {
17
17
InitialState {
18
- CounterApp . States. Fixed ( value: 10 )
18
+ CounterApp . States. Fixed ( counter : Counter ( value: 10 , min : 0 , max : 10 ) )
19
19
}
20
20
21
21
Feedbacks {
22
22
Feedback ( on: CounterApp . States. Decreasing. self,
23
23
strategy: . cancelOnNewState,
24
- sideEffect : CounterApp . SideEffects. decreaseEffect ( state: ) )
24
+ perform : CounterApp . SideEffects. decreaseEffect ( state: ) )
25
25
26
26
Feedback ( on: CounterApp . States. Increasing. self,
27
27
strategy: . cancelOnNewState,
28
- sideEffect : CounterApp . SideEffects. increaseEffect ( state: ) )
28
+ perform : CounterApp . SideEffects. increaseEffect ( state: ) )
29
29
}
30
30
. onStateReceived {
31
31
print ( " Counter: New state has been received: \( $0) " )
@@ -35,10 +35,37 @@ extension CounterApp.System {
35
35
}
36
36
37
37
Transitions {
38
- CounterApp . Transitions. fixedTransition
39
- CounterApp . Transitions. resetTransition
40
- CounterApp . Transitions. decreasingTransitions
41
- CounterApp . Transitions. increasingTransitions
38
+ From ( CounterApp . States. Fixed. self) { state in
39
+ On ( CounterApp . Events. TogglePause. self, transitionTo: CounterApp . States. Decreasing ( counter: state. counter, isPaused: false ) )
40
+ }
41
+
42
+ From ( AnyState . self) {
43
+ On ( CounterApp . Events. Reset. self) {
44
+ CounterApp . States. Fixed ( counter: Counter ( value: 10 , min: 0 , max: 10 ) )
45
+ }
46
+ }
47
+
48
+ From ( CounterApp . States. Decreasing. self) { state in
49
+ On ( CounterApp . Events. TogglePause. self, transitionTo: CounterApp . States. Decreasing ( counter: state. counter, isPaused: !state. isPaused) )
50
+ On ( CounterApp . Events. Decrease. self) {
51
+ guard !state. isPaused else { return state }
52
+ if state. counter. value == state. counter. min {
53
+ return CounterApp . States. Increasing ( counter: state. counter. increase ( ) , isPaused: false )
54
+ }
55
+ return CounterApp . States. Decreasing ( counter: state. counter. decrease ( ) , isPaused: false )
56
+ }
57
+ }
58
+
59
+ From ( CounterApp . States. Increasing. self) { state in
60
+ On ( CounterApp . Events. TogglePause. self, transitionTo: CounterApp . States. Increasing ( counter: state. counter, isPaused: !state. isPaused) )
61
+ On ( CounterApp . Events. Increase. self) {
62
+ guard !state. isPaused else { return state }
63
+ if state. counter. value == state. counter. max {
64
+ return CounterApp . States. Decreasing ( counter: state. counter. decrease ( ) , isPaused: false )
65
+ }
66
+ return CounterApp . States. Increasing ( counter: state. counter. increase ( ) , isPaused: false )
67
+ }
68
+ }
42
69
}
43
70
}
44
71
}
0 commit comments