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 StackBasedNavigation.md #2475

Merged
Merged
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 @@ -429,7 +429,7 @@ use the `XCTModify` helper:

```swift
await store.send(.path(.element(id: 0, action: .incrementButtonTapped))) {
XCTModify(&$0[id: 0], case: /Feature.Path.State.counter) {
XCTModify(&$0.path[id: 0], case: /Feature.Path.State.counter) {
$0.count = 4
}
}
Expand All @@ -439,15 +439,15 @@ The `XCTModify` function takes an `inout` piece of enum state as its first argum
path for its second argument, and then uses the case path to extract the payload in that case,
allow you to perform a mutation to it, and embed the data back into the enum. So, in the code
above we are subscripting into ID 0, isolating the `.counter` case of the `Path.State` enum,
and mutating the `count` to be 4 since it incremented by one. Further, if the case of `$0[id: 0]`
and mutating the `count` to be 4 since it incremented by one. Further, if the case of `$0.path[id: 0]`
didn't match the case path, then a test failure would be emitted.

Another option is to use ``StackState/subscript(id:case:)`` to simultaneously subscript into an
ID on the stack _and_ a case of the path enum:

```swift
await store.send(.path(.element(id: 0, action: .incrementButtonTapped))) {
$0[id: 0, case: /Feature.Path.State.counter]?.count = 4
$0.path[id: 0, case: /Feature.Path.State.counter]?.count = 4
}
```

Expand All @@ -458,7 +458,7 @@ Continuing with the test, we can send it one more time to see that the count goe

```swift
await store.send(.path(.element(id: 0, action: .incrementButtonTapped))) {
XCTModify(&$0[id: 0], case: /Feature.Path.State.counter) {
XCTModify(&$0.path[id: 0], case: /Feature.Path.State.counter) {
$0.count = 5
}
}
Expand Down