Composable Stacks: State Ergonomics

Episode #235 • May 15, 2023 • Subscriber-Only

We introduce a complementary StackState wrapper to our navigation tools to solve a few issues that came from repurposing the identified array type. Once implemented and integrated, we will put these tools’ superpowers to work by implementing two new features.

State Ergonomics
Introducing StackState
Integrating StackState
Introspecting StackState
New feature, existing stack
Next time: effect cancellation

Unlock This Episode

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


We’ve now cleaned up the reducer and the view and things are looking quite succinct.

However, we can take things much, much further. Let’s finally look at all this identifiable madness that we have let infect our code. We have needed to conform each of our features’ states to the Identifiable protocol, which typically does not make sense. We just kind of shoehorned it in by adding a randomly generated UUID. That was easy to do, but what wasn’t easy was to then further conform our Path.State enum to be identifiable, which forced us to define a conformance by switching over the enum and calling out to the id of each of our features. That code is a pain to maintain, and will need to be updated every time a new feature is added to the stack. And all of that was annoying enough without even talking about tests, which would be really annoying given all the uncontrolled UUIDs we just sprinkled throughout our code.

Stephen: Further, putting our features into a navigation stack also suddenly forced us to make our features’ state Hashable. That was easy enough to do as ideally all state structs are simple data types that can be automatically made Hashable, but also features can hold lots of state. We may have a really large feature with lots of child features, and hashing all of that data may be quite slow. We could provide a custom hash implementation that just hashes the ID that we’ve been forced to provide, but that is just more manual work to be done and it’s probably not correct to do. What if we did really want a proper Hashable implementation for the state that did hash all the data? We would be out of luck because we’ve trampled on that possibility due to all the strange choices we’ve been forced into.

So, let’s finally untangle ourselves from hashability and identifiability. We will create a new data type that behaves a lot like IdentifiedArray, but that is tuned specifically for navigation stacks.

Let’s try it out.

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


Composable navigation beta GitHub discussion

Brandon Williams & Stephen Celis • Monday Feb 27, 2023

In conjunction with the release of episode #224 we also released a beta preview of the navigation tools coming to the Composable Architecture.