This is a short one about an Undo button in the EPUB reader I'm building, and about a small change in how we decide whether Undo is still valid, which turned out to fix a whole class of bugs instead of the one I was looking at.
The reader has a settings sheet (font, margins, themes, auto-scroll and so on), and the sheet has a Reset button which puts every reading setting of the book back to the defaults, and also rewrites the format defaults that new books inherit. There was no way back from it, so one stray click and your carefully tuned settings were gone. The options were a confirmation dialog or an undo, and undo is the friendlier one, since it doesn't put a dialog in front of every click that was intentional.
The app uses The Composable Architecture (TCA), so the settings live in reducer state and every change goes through an action. The first version looked like what you'd probably write too:
case let . epubPreferencesResetTapped ( defaults ) : state . epubPreferencesBeforeReset = state .…