Prevent Invalid States
You can drastically improve the salad builder’s maintainability with one final tweak. The application uses four fields to represent view state: building, sending, success, and error. In this section, you will see how invalid configurations of these fields could lead to ambiguity and bugs. Then, you will fix the issue by consolidating the fields into one.
Combine the Fields
Here’s the problem: the four view state fields encapsulate one possible view state. Inside viewStep, you check the fields in an arbitrary order with if-else to pick what to display. First, you check sending and then building. You never bother checking the success field and you assume it’s True in the else branch.
That means you could display viewConfirmation ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access