Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update migration guide 1.5 #2615

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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