Menu

Making an Undo button check state instead of relying on every writer to clear it
📰

Making an Undo button check state instead of relying on every writer to clear it

DEV Community: ios·Darkø Tasevski·about 17 hours ago
#54lorS1E
#devtoios#devto#dev#expect#state
Long article (1203 words) — no AI summary yet.
Reading 0:00
15s threshold

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 .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.