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.

Observing Enums
Introduction
00:05
Getting rid of SwitchStore
00:56
Observable PresentationState
09:33
Observable enums
23:07
@ObservableState for enums
29:09
Next time: observing collections
42:53

Unlock This Episode

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

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.

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