Skip to content

Commit

Permalink
Update migration guide 1.5 (#2615)
Browse files Browse the repository at this point in the history
* Update 1.5 migration guide to include info about IdentifiedAction.

* wip
  • Loading branch information
mbrandonw authored Dec 5, 2023
1 parent dcde721 commit 9a7d5da
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,28 @@ ChildView(
)
```

Another common case you may encounter is when dealing with collections. It is common in the
Composable Architecture to use an `IdentifiedArray` in your feature's state and an
``IdentifiedAction`` in your feature's actions (see <doc:MigratingTo1.4#Identified-actions> for more
info on ``IdentifiedAction``). If you needed to scope your store down to one specific row of the
identified domain, previously you would have done so like this:

```swift
store.scope(
state: \.rows[id: id],
action: { .rows(.element(id: id, action: $0)) }
)
```

With case key paths it can be done simply like this:

```swift
store.scope(
state: \.rows[id: id],
action: \.rows[id: id]
)
```

These tricks should be enough for you to rewrite all of your store scopes using key paths, but if
you have any problems feel free to open a
[discussion](http://github.com/pointfreeco/swift-composable-architecture/discussions) on the repo.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ extension IdentifiedAction: Sendable where ID: Sendable, Action: Sendable {}
extension IdentifiedAction: Decodable where ID: Decodable, Action: Decodable {}
extension IdentifiedAction: Encodable where ID: Encodable, Action: Encodable {}

/// A convenience type alias for referring to an identified action of a given reducer's domain.
///
/// Instead of specifying the action like this:
///
/// ```swift
/// case rows(IdentifiedAction<ChildFeature.State.ID, ChildFeature.Action>)
/// ```
///
/// You can specify the reducer:
///
/// ```swift
/// case rows(IdentifiedActionOf<ChildFeature>)
/// ```
public typealias IdentifiedActionOf<R: Reducer> = IdentifiedAction<R.State.ID, R.Action>
where R.State: Identifiable

Expand Down

0 comments on commit 9a7d5da

Please sign in to comment.