Skip to content

Commit 9bdf1c4

Browse files
luoxiup4checo
authored andcommitted
typo: wait -> await (#1470)
(cherry picked from commit d7be3f523323b6d0a5d9e844001c3d08bf9d0bb8) # Conflicts: # README.md
1 parent 102f026 commit 9bdf1c4

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

README.md

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ In here we need to define a type for the feature's state, which consists of an i
108108
```swift
109109
struct Feature: ReducerProtocol {
110110
struct State: Equatable {
111-
var count = 0
112-
var numberFactAlert: String?
113-
}
111+
var count = 0
112+
var numberFactAlert: String?
113+
}
114114
}
115115
```
116116

@@ -120,12 +120,12 @@ We also need to define a type for the feature's actions. There are the obvious a
120120
struct Feature: ReducerProtocol {
121121
struct State: Equatable { }
122122
enum Action: Equatable {
123-
case factAlertDismissed
124-
case decrementButtonTapped
125-
case incrementButtonTapped
126-
case numberFactButtonTapped
127-
case numberFactResponse(TaskResult<String>)
128-
}
123+
case factAlertDismissed
124+
case decrementButtonTapped
125+
case incrementButtonTapped
126+
case numberFactButtonTapped
127+
case numberFactResponse(TaskResult<String>)
128+
}
129129
}
130130
```
131131

@@ -135,22 +135,22 @@ And then we implement the `reduce` method which is responsible for handling the
135135
struct Feature: ReducerProtocol {
136136
struct State: Equatable { }
137137
enum Action: Equatable { }
138-
138+
139139
func reduce(into state: inout State, action: Action) -> Effect<Action, Never> {
140-
switch action {
141-
case .factAlertDismissed:
142-
state.numberFactAlert = nil
143-
return .none
140+
switch action {
141+
case .factAlertDismissed:
142+
state.numberFactAlert = nil
143+
return .none
144144

145-
case .decrementButtonTapped:
146-
state.count -= 1
147-
return .none
145+
case .decrementButtonTapped:
146+
state.count -= 1
147+
return .none
148148

149-
case .incrementButtonTapped:
150-
state.count += 1
151-
return .none
149+
case .incrementButtonTapped:
150+
state.count += 1
151+
return .none
152152

153-
case .numberFactButtonTapped:
153+
case .numberFactButtonTapped:
154154
return .task { [count = state.count] in
155155
await .numberFactResponse(
156156
TaskResult {
@@ -161,17 +161,17 @@ struct Feature: ReducerProtocol {
161161
)
162162
}
163163
)
164-
}
164+
}
165165

166-
case let .numberFactResponse(.success(fact)):
167-
state.numberFactAlert = fact
168-
return .none
166+
case let .numberFactResponse(.success(fact)):
167+
state.numberFactAlert = fact
168+
return .none
169169

170-
case .numberFactResponse(.failure):
171-
state.numberFactAlert = "Could not load a number fact :("
172-
return .none
173-
}
174-
}
170+
case .numberFactResponse(.failure):
171+
state.numberFactAlert = "Could not load a number fact :("
172+
return .none
173+
}
174+
}
175175
}
176176
}
177177
```
@@ -281,8 +281,8 @@ struct MyApp: App {
281281
store: Store(
282282
initialState: Feature.State(),
283283
reducer: Feature()
284-
)
285284
)
285+
)
286286
}
287287
}
288288
```
@@ -345,8 +345,8 @@ Then we can use it in the `reduce` implementation:
345345
```swift
346346
case .numberFactButtonTapped:
347347
return .task { [count = state.count] in
348-
await .numberFactResponse(TaskResult { try wait self.numberFact(count) })
349-
}
348+
await .numberFactResponse(TaskResult { try await self.numberFact(count) })
349+
}
350350
```
351351

352352
And in the entry point of the application we can provide a version of the dependency that actually interacts with the real world API server:
@@ -397,7 +397,7 @@ await store.receive(.numberFactResponse(.success("0 is a good number Brent"))) {
397397
await store.send(.factAlertDismissed) {
398398
$0.numberFactAlert = nil
399399
}
400-
```
400+
```
401401

402402
We can also improve the ergonomics of using the `numberFact` dependency in our application. Over time the application may evolve into many features, and some of those features may also want access to `numberFact`, and explicitly passing it through all layers can get annoying. There is a process you can follow to “register” dependencies with the library, making them instantly available to any layer in the application.
403403

0 commit comments

Comments
 (0)