Observable Architecture: Observing Enums

Episode #262 • Dec 18, 2023 • Subscriber-Only

We’ve made structs and optionals observable in the Composable Architecture, eliminating the need for ViewStores and IfLetStores, so what about enums? If we can make enums observable, we could further eliminate the concept of the SwitchStore, greatly improving the ergonomics of working with enums in the library.

Previous episode
Observable Architecture: Observing Enums
Next episode
Locked

Unlock This Episode

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

Sign in with GitHub

Introduction

Brandon

So this is all looking absolutely incredible. We are finding that by having the view automatically subscribe to the minimal amount of state that it needs access to, we allow ourselves to greatly simplify the tools that the Composable Architecture provides. We no longer need to hide little efficiency tricks inside dedicated view helpers, like the IfLetStore, and instead we can just access the state directly, do a regular, vanilla Swift if let, and everything just works as we expect. This is going to have a huge impact on applications built with the Composable Architecture.

Stephen

But we can take things further. There are more special view helpers in the library that exist only because we needed a way to minimally observe state. One such example is the SwitchStore, which allows you to model your domains with enums while still allowing you to split off child stores focused in on one particular case of the enum. It’s a powerful tool, but turns out it is completely unnecessary in a world of observation.

Let’s take a look.

Getting rid of SwitchStore


Get started with our free plan

Our free plan includes 1 subscriber-only episode of your choice, access to 62 free episodes with transcripts and code samples, and weekly updates from our newsletter.

View plans and pricing