|
| 1 | +# Hints |
| 2 | + |
| 3 | +## General |
| 4 | + |
| 5 | +- Check out the [Elm Guide][elm-guide], which has a nice worked example that is similar. |
| 6 | + |
| 7 | +## 1. Define the Model type for the application |
| 8 | + |
| 9 | +- The `Model` contains the application's state - all the data that the application needs. |
| 10 | +- This application just needs a string to store the text in the Text Box. |
| 11 | +- It can be any type, but in any useful application it is always a [record][record]. |
| 12 | + |
| 13 | +## 2. Define the Msg type for the application |
| 14 | + |
| 15 | +- The `Msg` type is a defines the messages that are passed to the `update` function, to trigger specific changes in the model. |
| 16 | +- This application only needs one change to the model - updating the model when the text in the Text Box changes. |
| 17 | +- It can be any type, but in any useful application it is always a [custom type][custom-type]. |
| 18 | + |
| 19 | +## 3. Write the update function |
| 20 | + |
| 21 | +- In any useful application the update function will use a `case` statement to pattern match on the `Msg` parameter. |
| 22 | +- IN each branch of the case statement it will extract information it needs from the `Msg` parameter and return an updated `Model` |
| 23 | +- The `Model` should be a record, and [record update syntax][record-update-syntax] is normally used. |
| 24 | + |
| 25 | +## 4. Write the view function |
| 26 | + |
| 27 | +- The `view` function should probably return a `div` for the root element |
| 28 | +- The first child should be an `input`, with a `value` attribute for the current text, and an `nInput` attribute / event with the relevant variant of the `Msg`. |
| 29 | +- The second child should probably be another `div` with a `text`child stating whether the text is a palindrome or not. |
| 30 | + |
| 31 | +## 5. Write the init function |
| 32 | + |
| 33 | +- This should simply return a `Model` with sensible default values (probably an empty string). |
| 34 | + |
| 35 | +## 6. Write the main function |
| 36 | + |
| 37 | +- The main function should just called [`Browser.sandbox`][browser-sandbox] |
| 38 | +- `Browser.sandbox` requires a [record][record] argument with the `init`, `update` and `view` functions. |
| 39 | + |
| 40 | +[elm-guide]: https://guide.elm-lang.org/architecture/text_fields |
| 41 | +[record]: https://elm-lang.org/docs/records |
| 42 | +[custom-type]: https://guide.elm-lang.org/types/custom_types.html |
| 43 | +[record-update-syntax]: https://elm-lang.org/docs/records#updating-records |
| 44 | +[browser-sandbox]: https://package.elm-lang.org/packages/elm/browser/latest/Browser#sandbox |
0 commit comments