|
8 | 8 | @ContentAndMedia {
|
9 | 9 | Side effects are by far the most important aspect of feature development. They are what allow
|
10 | 10 | us to communicate with the outside world, such as making API requests, interacting with file
|
11 |
| - systems, and performing time-based asynchrony. Without them our applications could not do |
| 11 | + systems, and performing time-based asynchrony. Without them, our applications could not do |
12 | 12 | anything of real value for our users.
|
13 | 13 |
|
14 | 14 | However, side effects are also the most complex part of our features. State mutations are
|
15 |
| - simple processes. If you run the reducer with the same piece of state and same action you will |
| 15 | + simple processes. If you run the reducer with the same piece of state and same action, you will |
16 | 16 | always get the same result. But effects are susceptible to the vagaries of the outside world,
|
17 |
| - such as network connectivity, disk permissions, and more. Each time you run an effect you |
| 17 | + such as network connectivity, disk permissions, and more. Each time you run an effect, you |
18 | 18 | can get back a completely different answer.
|
19 | 19 |
|
20 | 20 | Let's start by seeing why we can't simply perform effectful work directly in our
|
|
42 | 42 | @Step {
|
43 | 43 | We will also add a progress view at the bottom to display while we are loading the fact,
|
44 | 44 | and we will unwrap a bit of optional state to display the fact. We are using the
|
45 |
| - `isLoading` and `fact` state to accomplish this, neither of which exist in the counter |
| 45 | + `isLoading` and `fact` state to accomplish this, neither of which exists in the counter |
46 | 46 | feature yet, but will soon.
|
47 | 47 |
|
48 | 48 | @Code(name: "CounterFeature.swift", file: 02-01-code-0002.swift)
|
|
63 | 63 | Let's add the additional state and actions that have been dictated to us by the view.
|
64 | 64 | We know we need some `fact` and `isLoading` state, and we need a `factButtonTapped` action.
|
65 | 65 | We can also implement that action in the reducer by flipping `isLoading` to `true`, and
|
66 |
| - we'll clear the `fact` state when any button is tapped. And finally we will return `.none` |
| 66 | + we'll clear the `fact` state when any button is tapped. And finally, we will return `.none` |
67 | 67 | just like we did in all the other cases.
|
68 | 68 |
|
69 | 69 | @Code(name: "CounterFeature.swift", file: 02-01-code-0004.swift)
|
|
82 | 82 |
|
83 | 83 | The Composable Architecture separates the simple, pure transformations of state from the
|
84 | 84 | complex, messy side effects. It is one of the core tenets of the library and there are a lot
|
85 |
| - of benefits to doing so. Luckily for us the library gives us a tool that is appropriate |
| 85 | + of benefits to doing so. Luckily for us, the library gives us a tool that is appropriate |
86 | 86 | for executing side effects. It is called ``ComposableArchitecture/EffectTask`` and it is
|
87 | 87 | explored in the next section.
|
88 | 88 | }
|
|
214 | 214 | "Stop timer", we will see that the timer did not stop.
|
215 | 215 |
|
216 | 216 | @Step {
|
217 |
| - To fix the bug we can leverage a powerful feature of the Composable Architecture known as |
| 217 | + To fix the bug, we can leverage a powerful feature of the Composable Architecture known as |
218 | 218 | "effect cancellation". We can mark any effect as cancellable using the
|
219 | 219 | ``ComposableArchitecture/EffectPublisher/cancellable(id:cancelInFlight:)-29q60`` method
|
220 | 220 | by providing an ID, and then at a later time we can cancel that effect using
|
|
0 commit comments