Skip to content

Commit 9a7d5da

Browse files
authored
Update migration guide 1.5 (#2615)
* Update 1.5 migration guide to include info about IdentifiedAction. * wip
1 parent dcde721 commit 9a7d5da

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

Sources/ComposableArchitecture/Documentation.docc/Articles/MigratingTo1.5.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,28 @@ ChildView(
142142
)
143143
```
144144

145+
Another common case you may encounter is when dealing with collections. It is common in the
146+
Composable Architecture to use an `IdentifiedArray` in your feature's state and an
147+
``IdentifiedAction`` in your feature's actions (see <doc:MigratingTo1.4#Identified-actions> for more
148+
info on ``IdentifiedAction``). If you needed to scope your store down to one specific row of the
149+
identified domain, previously you would have done so like this:
150+
151+
```swift
152+
store.scope(
153+
state: \.rows[id: id],
154+
action: { .rows(.element(id: id, action: $0)) }
155+
)
156+
```
157+
158+
With case key paths it can be done simply like this:
159+
160+
```swift
161+
store.scope(
162+
state: \.rows[id: id],
163+
action: \.rows[id: id]
164+
)
165+
```
166+
145167
These tricks should be enough for you to rewrite all of your store scopes using key paths, but if
146168
you have any problems feel free to open a
147169
[discussion](http://github.com/pointfreeco/swift-composable-architecture/discussions) on the repo.

Sources/ComposableArchitecture/Reducer/Reducers/ForEachReducer.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ extension IdentifiedAction: Sendable where ID: Sendable, Action: Sendable {}
4242
extension IdentifiedAction: Decodable where ID: Decodable, Action: Decodable {}
4343
extension IdentifiedAction: Encodable where ID: Encodable, Action: Encodable {}
4444

45+
/// A convenience type alias for referring to an identified action of a given reducer's domain.
46+
///
47+
/// Instead of specifying the action like this:
48+
///
49+
/// ```swift
50+
/// case rows(IdentifiedAction<ChildFeature.State.ID, ChildFeature.Action>)
51+
/// ```
52+
///
53+
/// You can specify the reducer:
54+
///
55+
/// ```swift
56+
/// case rows(IdentifiedActionOf<ChildFeature>)
57+
/// ```
4558
public typealias IdentifiedActionOf<R: Reducer> = IdentifiedAction<R.State.ID, R.Action>
4659
where R.State: Identifiable
4760

0 commit comments

Comments
 (0)