I want to use the new customDump and diff features in my reducer. Do I replace .debug()?

Loving the newest releases, and am eager to do something new with the customDump command in the swift-custom-dump package.
A good use out of the box would be to call it at the end of the reducer (where I now have a call to debug()). When I update a record in an array I'm getting a diff that includes all the unaltered objects as well as the changed ones, and I'd prefer something similar to the print(diff(a, b)) where a is the previous call to the reducer and b is the current. and I'd see something like ... (4 unchanged) instead of the member objects listed with all their unchanged details. Where do I start?

Hi @Mozahler, what you are describing should already be the default behavior if you are running the newest version of TCA in your code base.

For example, if I open the repo's workspace, run the Todos application, and add a bunch of todos, I see the following printed to the console when I complete a todo:

received action:
  AppAction.todo(
    id: UUID(FED4EAE4-F029-47D0-9FBB-5A58372629A1),
    action: TodoAction.checkBoxToggled
  )
  AppState(
    editMode: EditMode.inactive,
    filter: Filter.all,
    todos: [
      … (4 unchanged),
      [4]: Todo(
        description: "",
        id: UUID(FED4EAE4-F029-47D0-9FBB-5A58372629A1),
-       isComplete: false
+       isComplete: true
      ),
      … (5 unchanged)
    ]
  )

If you are not seeing this behavior then you may need to update your packages to use the newest release of TCA.

I'm using 0.25.1. OK. I'm seeing it in the output now. I need to determine why it's still more verbose than I expect. Thanks for the quick response!

Can you share some output logs you are seeing from using .debug()?

Here's the output from a REST query to Stack Overflow. I don't think there's anything wrong with it. It's just a lot to wade through.
"""

received action:
  SimplySoAction.processQuestionQueryResult(
    Result.success(
      [
        [0]: Question(
          id: 68864217,
          score: 3,
          title: "SwiftUI - Calculate height for long GeometryReader inside ScrollView",
          body: nil,
          tags: [
            [0]: "ios",
            [1]: "swiftui",
            [2]: "geometryreader",
            [3]: "swiftui-scrollview"
          ],
          owner: User(
            aboutMe: nil,
            acceptRate: 83,
            accountId: 2236007,
            answerCount: nil,
            badgeCounts: nil,
            creationDate: nil,
            displayName: "Big_Chair",
            lastAccessDate: nil,
            lastModifiedDate: nil,
            profileImage: URL(https://i.stack.imgur.com/h3gwk.jpg?s=128&g=1),
            questionCount: nil,
            reputation: 912,
            userId: 1972372,
            viewCount: nil
          ),
          answerCount: 2,
          viewCount: 93,
          acceptedAnswerId: nil,
          date: Date(2021-08-20T14:57:07.000Z)
        ),
        [1]: Question(
          id: 68878275,
          score: 2,
          title: "How to apply a dynamic rotation to a map using SwiftUI",
          body: nil,
          tags: [
            [0]: "swift",
            [1]: "swiftui",
            [2]: "rotation",
            [3]: "mapbox",
            [4]: "safearea"
          ],
          owner: User(
            aboutMe: nil,
            acceptRate: nil,
            accountId: 21095035,
            answerCount: nil,
            badgeCounts: nil,
            creationDate: nil,
            displayName: "nickcoding2",
            lastAccessDate: nil,
            lastModifiedDate: nil,
            profileImage: URL(https://www.gravatar.com/avatar/8bdb1ef6b5a6fe52f4acaad280472507?s=128&d=identicon&r=PG&f=1),
            questionCount: nil,
            reputation: 133,
            userId: 15506187,
            viewCount: nil
          ),
          answerCount: 1,
          viewCount: 53,
          acceptedAnswerId: nil,
          date: Date(2021-08-22T03:27:58.000Z)
        ),
        [2]: Question(
          id: 68900888,
          score: 2,
          title: "How do I properly perform Dependency Injection into SwiftUI StateObjects?",
          body: nil,
          tags: [
            [0]: "ios",
            [1]: "swift",
            [2]: "dependency-injection",
            [3]: "swiftui"
          ],
          owner: User(
            aboutMe: nil,
            acceptRate: nil,
            accountId: 6989074,
            answerCount: nil,
            badgeCounts: nil,
            creationDate: nil,
            displayName: "Mai Anh Vu",
            lastAccessDate: nil,
            lastModifiedDate: nil,
            profileImage: URL(https://www.gravatar.com/avatar/5c15a1f87f1e7150ee9f9100d1f37c65?s=128&d=identicon&r=PG),
            questionCount: nil,
            reputation: 29,
            userId: 5358977,
            viewCount: nil
          ),
          answerCount: 0,
          viewCount: 35,
          acceptedAnswerId: nil,
          date: Date(2021-08-24T01:54:25.000Z)
        )
      ]
    )
  )
  SimplySoState(
    questions: [
+     [0]: Question(
+       id: 68864217,
+       score: 3,
+       title: "SwiftUI - Calculate height for long GeometryReader inside ScrollView",
+       body: nil,
+       tags: [
+         [0]: "ios",
+         [1]: "swiftui",
+         [2]: "geometryreader",
+         [3]: "swiftui-scrollview"
+       ],
+       owner: User(
+         aboutMe: nil,
+         acceptRate: 83,
+         accountId: 2236007,
+         answerCount: nil,
+         badgeCounts: nil,
+         creationDate: nil,
+         displayName: "Big_Chair",
+         lastAccessDate: nil,
+         lastModifiedDate: nil,
+         profileImage: URL(https://i.stack.imgur.com/h3gwk.jpg?s=128&g=1),
+         questionCount: nil,
+         reputation: 912,
+         userId: 1972372,
+         viewCount: nil
+       ),
+       answerCount: 2,
+       viewCount: 93,
+       acceptedAnswerId: nil,
+       date: Date(2021-08-20T14:57:07.000Z)
+     ),
+     [1]: Question(
+       id: 68878275,
+       score: 2,
+       title: "How to apply a dynamic rotation to a map using SwiftUI",
+       body: nil,
+       tags: [
+         [0]: "swift",
+         [1]: "swiftui",
+         [2]: "rotation",
+         [3]: "mapbox",
+         [4]: "safearea"
+       ],
+       owner: User(
+         aboutMe: nil,
+         acceptRate: nil,
+         accountId: 21095035,
+         answerCount: nil,
+         badgeCounts: nil,
+         creationDate: nil,
+         displayName: "nickcoding2",
+         lastAccessDate: nil,
+         lastModifiedDate: nil,
+         profileImage: URL(https://www.gravatar.com/avatar/8bdb1ef6b5a6fe52f4acaad280472507?s=128&d=identicon&r=PG&f=1),
+         questionCount: nil,
+         reputation: 133,
+         userId: 15506187,
+         viewCount: nil
+       ),
+       answerCount: 1,
+       viewCount: 53,
+       acceptedAnswerId: nil,
+       date: Date(2021-08-22T03:27:58.000Z)
+     ),
+     [2]: Question(
+       id: 68900888,
+       score: 2,
+       title: "How do I properly perform Dependency Injection into SwiftUI StateObjects?",
+       body: nil,
+       tags: [
+         [0]: "ios",
+         [1]: "swift",
+         [2]: "dependency-injection",
+         [3]: "swiftui"
+       ],
+       owner: User(
+         aboutMe: nil,
+         acceptRate: nil,
+         accountId: 6989074,
+         answerCount: nil,
+         badgeCounts: nil,
+         creationDate: nil,
+         displayName: "Mai Anh Vu",
+         lastAccessDate: nil,
+         lastModifiedDate: nil,
+         profileImage: URL(https://www.gravatar.com/avatar/5c15a1f87f1e7150ee9f9100d1f37c65?s=128&d=identicon&r=PG),
+         questionCount: nil,
+         reputation: 29,
+         userId: 5358977,
+         viewCount: nil
+       ),
+       answerCount: 0,
+       viewCount: 35,
+       acceptedAnswerId: nil,
+       date: Date(2021-08-24T01:54:25.000Z)
+     )
    ],
    currentTab: TabValues.Asked,
    userInfo: User(…),
    userInfoSheet: UserSheet(…),
    answers: Set([]),
    isLoading: false,
    isConnected: true,
    badgeCount: 0
  )

received action:
  SimplySoAction.handleUserInfo(
    Result.success(
      [
        [0]: User(
          aboutMe: nil,
          acceptRate: 82,
          accountId: 6683987,
          answerCount: nil,
          badgeCounts: BadgeCount(
            bronze: 42,
            silver: 25,
            gold: 6
          ),
          creationDate: Date(2015-07-25T18:57:36.000Z),
          displayName: "Mozahler",
          lastAccessDate: Date(2021-08-25T17:29:46.000Z),
          lastModifiedDate: Date(2021-06-01T19:05:00.000Z),
          profileImage: URL(https://i.stack.imgur.com/AXyaZ.jpg?s=128&g=1),
          questionCount: nil,
          reputation: 3831,
          userId: 5156054,
          viewCount: nil
        )
      ]
    )
  )
  SimplySoState(
    questions: […],
    currentTab: TabValues.Asked,
    userInfo: User(…),
    userInfoSheet: UserSheet(
-     id: UUID(1B5F81DD-3D18-4A7D-AC78-859EB92A7262),
+     id: UUID(26166E08-AEC6-4211-9FD7-BC4B11CED53F),
      user: User(…)
    ),
    answers: Set([]),
    isLoading: false,
    isConnected: true,
    badgeCount: 0
  )

received action:
  SimplySoAction.processQuestionQueryResult(
    Result.success(
      [
        [0]: Question(
          id: 68864217,
          score: 3,
          title: "SwiftUI - Calculate height for long GeometryReader inside ScrollView",
          body: nil,
          tags: [
            [0]: "ios",
            [1]: "swiftui",
            [2]: "geometryreader",
            [3]: "swiftui-scrollview"
          ],
          owner: User(
            aboutMe: nil,
            acceptRate: 83,
            accountId: 2236007,
            answerCount: nil,
            badgeCounts: nil,
            creationDate: nil,
            displayName: "Big_Chair",
            lastAccessDate: nil,
            lastModifiedDate: nil,
            profileImage: URL(https://i.stack.imgur.com/h3gwk.jpg?s=128&g=1),
            questionCount: nil,
            reputation: 912,
            userId: 1972372,
            viewCount: nil
          ),
          answerCount: 2,
          viewCount: 93,
          acceptedAnswerId: nil,
          date: Date(2021-08-20T14:57:07.000Z)
        ),
        [1]: Question(
          id: 68878275,
          score: 2,
          title: "How to apply a dynamic rotation to a map using SwiftUI",
          body: nil,
          tags: [
            [0]: "swift",
            [1]: "swiftui",
            [2]: "rotation",
            [3]: "mapbox",
            [4]: "safearea"
          ],
          owner: User(
            aboutMe: nil,
            acceptRate: nil,
            accountId: 21095035,
            answerCount: nil,
            badgeCounts: nil,
            creationDate: nil,
            displayName: "nickcoding2",
            lastAccessDate: nil,
            lastModifiedDate: nil,
            profileImage: URL(https://www.gravatar.com/avatar/8bdb1ef6b5a6fe52f4acaad280472507?s=128&d=identicon&r=PG&f=1),
            questionCount: nil,
            reputation: 133,
            userId: 15506187,
            viewCount: nil
          ),
          answerCount: 1,
          viewCount: 53,
          acceptedAnswerId: nil,
          date: Date(2021-08-22T03:27:58.000Z)
        ),
        [2]: Question(
          id: 68900888,
          score: 2,
          title: "How do I properly perform Dependency Injection into SwiftUI StateObjects?",
          body: nil,
          tags: [
            [0]: "ios",
            [1]: "swift",
            [2]: "dependency-injection",
            [3]: "swiftui"
          ],
          owner: User(
            aboutMe: nil,
            acceptRate: nil,
            accountId: 6989074,
            answerCount: nil,
            badgeCounts: nil,
            creationDate: nil,
            displayName: "Mai Anh Vu",
            lastAccessDate: nil,
            lastModifiedDate: nil,
            profileImage: URL(https://www.gravatar.com/avatar/5c15a1f87f1e7150ee9f9100d1f37c65?s=128&d=identicon&r=PG),
            questionCount: nil,
            reputation: 29,
            userId: 5358977,
            viewCount: nil
          ),
          answerCount: 0,
          viewCount: 35,
          acceptedAnswerId: nil,
          date: Date(2021-08-24T01:54:25.000Z)
        )
      ]
    )
  )
  (No state changes)

"""

Ah I see. Everything being printed is the data inside the action. That data can't be diff'd because there's no before and after. It's just data coming in from the outside world.

If you want to omit the data from the action to make things easier to read you can provide the argument actionFormat: .labelsOnly to the .debug() method:

Thank you. Of course there's a parameter. Next time I'll look first. Appreciate your help!

You can also use a CasePath to focus on just some actions, or just part of some actions, using the action argument of the four-argument debug operator. By constructing a custom CasePath<Action, Any>, you can be very specific about what parts of each action you print.

Thank you, Rob. Definitely food for thought. Time to ruminate.