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
Changes from 1 commit
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
Next Next commit
Update 1.5 migration guide to include info about IdentifiedAction.
mbrandonw committed Dec 5, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
addaleax Anna Henningsen
commit 3a577128d7323a95522e379edda3eec2621ee7f8
Original file line number Diff line number Diff line change
@@ -142,6 +142,27 @@ 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. 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.
Original file line number Diff line number Diff line change
@@ -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