July 2019
Intermediate to advanced
310 pages
7h 26m
English
The update function suffers from code duplication and unnecessary complexity. In this section, you will simplify it by reducing the messages it handles. You will learn how to collapse multiple message values into one parameterized message value.
Look for the update function near the bottom of SaladBuilder.elm. This function is over 100 lines, so we have a problem.
| | update : Msg -> Model -> ( Model, Cmd Msg ) |
| | update msg model = |
| | case msg of |
| | SelectLettuce -> |
| | ( { model | base = Lettuce } |
| | , Cmd.none |
| | ) |
| | -- other branches |
Notice the duplication where we handle the ToggleTomatoes, ToggleCucumbers, and ToggleOnions messages. Surprisingly, we have duplication with the other salad-related messages for ...
Read now
Unlock full access