Shared State in Practice: SyncUps: Part 2

Episode #278 • May 6, 2024 • Subscriber-Only

We finish refactoring the SyncUps application to use the Composable Architecture’s all new state sharing tools. We will see that we can delete hundreds of lines of boilerplate of coordination between parent and child features, and we won’t have to sacrifice any testability, including the exhaustive testability provided by the library.

SyncUps: Part 2
Introduction
00:00
Updating tests
01:16
Getting rid of even more delegate actions
11:46
Fixing more tests
25:01
Next time: isowords
33:53

Unlock This Episode

Our Free plan includes 1 subscriber-only episode of your choice, plus weekly updates from our newsletter.

Introduction

Brandon: We now have two significant parts of the application using shared state: the list feature uses the @Shared property wrapper to persist a collection of sync ups to disk whenever the data changes, and the detail feature uses @Shared to express that it wants to make changes to a piece of state that are visible elsewhere. It’s awesome to see how everything hooks up to each other, and it’s very reminiscent of how bindings work in vanilla SwiftUI. In fact, we do like to think of @Shared as being the Composable Architecture version of bindings from SwiftUI.

Stephen: So, this seems great, but how does it affect tests? We are now doing two things in our state that historically do not play nicely with testing. First, we have persistence, which means some interaction with the file system, which is a global blob of data that anyone can write to. And we have state sharing, which means a reference type is involved, and reference types are notoriously tricky to test since they don’t have a well-accepted notion of equality and since they cannot be copied.

Well, luckily our @Shared property wrapper has none of these issues. It is completely testable, and even exhaustively testable.

Let’s take a look.

This episode is for subscribers only.

Subscribe to Point-Free

Access this episode, plus all past and future episodes when you become a subscriber.

See plans and pricing

Already a subscriber? Log in