Skip to content

Commit

Permalink
Fix tutorial diffs (#2642)
Browse files Browse the repository at this point in the history
While tutorials appear to compile just fine when files are referenced as
strings and omitting the file suffix, it mysteriously breaks the diffing
between each step. This PR fixes things.
  • Loading branch information
stephencelis authored Dec 11, 2023
1 parent 897cf6a commit 88d995d
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@
> Note: We conform `State` and `Action` to the `Equatable` protocol in order to test this
> feature later.

@Code(name: "ContactsFeature.swift", file: "02-01-01-code-0000")
@Code(name: "ContactsFeature.swift", file: 02-01-01-code-0000.swift)
}

@Step {
Add a view that holds onto a ``ComposableArchitecture/Store`` of the `ContactsFeature`
and observes the store in order to show a list of contacts and send actions.

@Code(name: "ContactsFeature.swift", file: "02-01-01-code-0001", reset: true)
@Code(name: "ContactsFeature.swift", file: 02-01-01-code-0001.swift, reset: true)
}

@Step {
Add a preview with a few stubbed contacts already in the state so that we can see what
the feature looks like.

@Code(name: "ContactsFeature.swift", file: "02-01-01-code-0002", reset: true) {
@Code(name: "ContactsFeature.swift", file: 02-01-01-code-0002.swift, reset: true) {
@Image(source: "ch02-sub01-sec01-image-0001")
}
}
Expand All @@ -50,20 +50,20 @@
button for dismissing, and a "Save" button that when tapped should dismiss the feature
_and_ add the contact to the list of contacts in the parent.

@Code(name: "AddContactFeature.swift", file: "02-01-01-code-0003", reset: true)
@Code(name: "AddContactFeature.swift", file: 02-01-01-code-0003.swift, reset: true)
}

@Step {
Add a view that holds onto a ``ComposableArchitecture/Store`` of the `AddContactFeature`
and observes the state in order to show a text field for the contact name and send actions.

@Code(name: "AddContactFeature.swift", file: "02-01-01-code-0004", reset: true)
@Code(name: "AddContactFeature.swift", file: 02-01-01-code-0004.swift, reset: true)
}

@Step {
Add a preview so that we can see what the feature looks like.

@Code(name: "AddContactFeature.swift", file: "02-01-01-code-0005", reset: true) {
@Code(name: "AddContactFeature.swift", file: 02-01-01-code-0005.swift, reset: true) {
@Image(source: "ch02-sub01-sec01-image-0002")
}
}
Expand All @@ -87,7 +87,7 @@
few steps. Go back to the ContactsFeature.swift file where we built the `ContactsFeature`
reducer for handling the logic and behavior of the list of contacts.

@Code(name: "ContactsFeature.swift", file: "02-01-02-code-0000")
@Code(name: "ContactsFeature.swift", file: 02-01-02-code-0000.swift)
}

@Step {
Expand All @@ -98,7 +98,7 @@
A `nil` value represents that the "Add Contacts" feature is not presented, and a non-`nil`
value represents that it is presented.

@Code(name: "ContactsFeature.swift", file: "02-01-02-code-0001")
@Code(name: "ContactsFeature.swift", file: 02-01-02-code-0001.swift)
}

@Step {
Expand All @@ -107,15 +107,15 @@

This allows the parent to observe every action sent from the child feature.

@Code(name: "ContactsFeature.swift", file: "02-01-02-code-0002")
@Code(name: "ContactsFeature.swift", file: 02-01-02-code-0002.swift)
}

@Step {
Since a new case has been added to the action enum we must now handle it in the main
reducer. For now we will do nothing for this case and return `.none`, but soon we will do
more here.

@Code(name: "ContactsFeature.swift", file: "02-01-02-code-0003")
@Code(name: "ContactsFeature.swift", file: 02-01-02-code-0003.swift)
}

@Step {
Expand All @@ -128,7 +128,7 @@
automatically handles effect cancellation when the child feature is dismissed, and a lot
more. See the documentation for more information.

@Code(name: "ContactsFeature.swift", file: "02-01-02-code-0004")
@Code(name: "ContactsFeature.swift", file: 02-01-02-code-0004.swift)
}

That is all it takes to integrate the two features' domains together. Before moving onto the
Expand All @@ -140,7 +140,7 @@
When the "+" button is tapped in the contacts list feature we can now populate the
`addContact` state to represent that the feature should be presented.

@Code(name: "ContactsFeature.swift", file: "02-01-02-code-0005")
@Code(name: "ContactsFeature.swift", file: 02-01-02-code-0005.swift)
}

@Step {
Expand All @@ -152,15 +152,15 @@
> ``ComposableArchitecture/PresentationAction/presented(_:)`` case in order to listen for
> actions inside the "Add Contact" feature.

@Code(name: "ContactsFeature.swift", file: "02-01-02-code-0006")
@Code(name: "ContactsFeature.swift", file: 02-01-02-code-0006.swift)
}

@Step {
When the "Save" button is tapped _inside_ the "Add Contacts" feature we want to not only
dismiss the feature, but we also want to add the new contact to the collection of contacts
held in `ContactsFeature.State`.

@Code(name: "ContactsFeature.swift", file: "02-01-02-code-0007")
@Code(name: "ContactsFeature.swift", file: 02-01-02-code-0007.swift)
}

That is all it takes to implement communication between parent and child features. The parent
Expand All @@ -182,7 +182,7 @@
and we have a navigation title and toolbar. We need to figure out how to present a sheet
in this view whenever the `addContact` state flips to non-`nil`.

@Code(name: "ContactsFeature.swift", file: "02-01-02-code-0008", reset: true)
@Code(name: "ContactsFeature.swift", file: 02-01-02-code-0008.swift, reset: true)
}

The library comes with a variety of tools that mimic SwiftUI's native navigation tools (such
Expand All @@ -195,7 +195,7 @@
store will be derived focused only on the `AddContactFeature` domain, which is what you can
pass to the `AddContactView`.

@Code(name: "ContactsFeature.swift", file: "02-01-02-code-0009")
@Code(name: "ContactsFeature.swift", file: 02-01-02-code-0009.swift)
}

@Step {
Expand Down Expand Up @@ -225,29 +225,29 @@
`AddContactFeature`. This enum will describe all the actions that the parent can listen for
and interpret. It allows the child feature to directly tell the parent what it wants done.

@Code(name: "AddContactFeature.swift", file: 02-01-04-code-0000, previousFile: 02-01-04-code-0000-previous)
@Code(name: "AddContactFeature.swift", file: 02-01-04-code-0000.swift, previousFile: 02-01-04-code-0000-previous.swift)
}

@Step {
Handle the new case in the reducer, but we should never actually perform any logic in this
case. Only the parent should listen for `delegate` actions and respond accordingly.

@Code(name: "AddContactFeature.swift", file: 02-01-04-code-0001)
@Code(name: "AddContactFeature.swift", file: 02-01-04-code-0001.swift)
}

@Step {
Anytime we want the child feature to communicate to the parent we will return an effect that
immediately and synchronously sends a delegate action. For example, when the "Save" button
is tapped, we will send the `saveContact` action.

@Code(name: "AddContactFeature.swift", file: 02-01-04-code-0002)
@Code(name: "AddContactFeature.swift", file: 02-01-04-code-0002.swift)
}

@Step {
Go back to ContactsFeature.swift and update the reducer to listen for delegate actions to
figure out when it is time to dismiss or save the contact.

@Code(name: "ContactsFeature.swift", file: 02-01-04-code-0003, previousFile: 02-01-04-code-0003-previous)
@Code(name: "ContactsFeature.swift", file: 02-01-04-code-0003.swift, previousFile: 02-01-04-code-0003-previous.swift)
}

The application should work exactly as it did before the "delegate action" refactor, but now
Expand All @@ -262,7 +262,7 @@
``ComposableArchitecture/DismissEffect``. This is a value that allows child features to
dismiss themselves without any direct contact with the parent feature.

@Code(name: "AddContactFeature.swift", file: 02-01-04-code-0004, previousFile: 02-01-04-code-0004-previous)
@Code(name: "AddContactFeature.swift", file: 02-01-04-code-0004.swift, previousFile: 02-01-04-code-0004-previous.swift)
}

@Step {
Expand All @@ -273,23 +273,23 @@
> Note: The `dismiss` dependency is asynchronous which means it is only appropriate to
> invoke from an effect.

@Code(name: "AddContactFeature.swift", file: 02-01-04-code-0005)
@Code(name: "AddContactFeature.swift", file: 02-01-04-code-0005.swift)
}

@Step {
Remove the `cancel` action from the `Delegate` enum because it is no longer needed. We do
not need to explicitly communicate to the parent that it should dismiss the child. That is
all handled by the ``ComposableArchitecture/DismissEffect``.

@Code(name: "AddContactFeature.swift", file: 02-01-04-code-0006)
@Code(name: "AddContactFeature.swift", file: 02-01-04-code-0006.swift)
}

@Step {
Go back to ContactsFeature.swift. We can also remove the `cancel` logic from the
`ContactsFeature` reducer and it is no longer necessary to explicitly `nil` out the
`addContact` state. That is already taken care of.

@Code(name: "ContactsFeature.swift", file: 02-01-04-code-0007, previousFile: 02-01-04-code-0007-previous)
@Code(name: "ContactsFeature.swift", file: 02-01-04-code-0007.swift, previousFile: 02-01-04-code-0007-previous.swift)
}
}
}
Expand Down
Loading

0 comments on commit 88d995d

Please sign in to comment.