Skip to content

Commit d5d2e02

Browse files
authored
Update 1.25 migration guide for enum alerts (#3904)
Alerts and confirmation dialogs held in `@Reducer enum`s will require a bit of extra ceremony to be 2.0-compatible, but 2.0 will come with more flexible tooling around handling prompts.
1 parent a66ba01 commit d5d2e02

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

Examples/SyncUps/SyncUps/SyncUpDetail.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ struct SyncUpDetail {
88
case alert(AlertState<Alert>)
99
case edit(SyncUpForm)
1010

11+
@CasePathable
12+
enum Action {
13+
case alert(Alert)
14+
case edit(SyncUpForm.Action)
15+
}
16+
1117
@CasePathable
1218
enum Alert {
1319
case confirmDeletion

Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/ComposableArchitecture/Documentation.docc/Articles/MigrationGuides/MigratingTo1.25.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ directly to a specific case of a destination enum, you now scope to the entire d
3939
chain into the individual case:
4040

4141
```diff
42-
-.alert($store.scope(state: \.destination?.alert, action: \.destination.alert))
43-
+.alert($store.scope(state: \.$destination, action: \.destination).alert)
44-
4542
-.sheet(item: $store.scope(state: \.destination?.edit, action: \.destination.edit)) {
4643
+.sheet(item: $store.scope(state: \.$destination, action: \.destination).edit) {
4744
```
@@ -62,6 +59,28 @@ bindings to `Bool` bindings:
6259
+) {
6360
```
6461

62+
Another important difference is that holding non-feature state in a destination enum with an
63+
associated action (such as the action of an `AlertState<Action>`) requires an explicit `Action` enum
64+
definition:
65+
66+
```diff
67+
@Reducer enum Destination {
68+
case alert(AlertState<Alert>)
69+
case settings(Settings)
70+
71+
+ @CasePathable enum Action {
72+
+ case alert(Alert)
73+
+ case settings(Settings.Action)
74+
+ }
75+
76+
enum Alert {
77+
case .deleteTapped
78+
}
79+
}
80+
```
81+
82+
ComposableArchitecture 2.0 will have newer tools for handling prompts.
83+
6584
### Streamlined `onChange` operator
6685

6786
A new overload of the `onChange` operator has been added that directly returns an effect instead

0 commit comments

Comments
 (0)