Skip to content

Commit c7966bc

Browse files
committed
Add hints
1 parent 0805de5 commit c7966bc

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

concepts/web-applications-1/about.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type alias Model =
1616

1717
`update` is a function that gets called with a `Msg` when there's a change (like the user clicking a button).
1818
It takes the current `Model` and the `Msg`, and returns a new `Model`.
19+
The `Msg` can be any type, but in any useful application it is always a [custom type][custom-type].
1920

2021
```elm
2122
type Msg
@@ -78,6 +79,7 @@ init =
7879
```
7980

8081
[record]: https://elm-lang.org/docs/records
82+
[custom-type]: https://guide.elm-lang.org/types/custom_types.html
8183
[elm-guide-text-fields]: https://guide.elm-lang.org/architecture/text_fields
8284
[html-elements]: https://package.elm-lang.org/packages/elm/html/latest/Html
8385
[element-attributes]: https://package.elm-lang.org/packages/elm/html/latest/Html-Attributes
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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

exercises/concept/paulas-palindromes/.docs/instructions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ Inside this root element, there should be an `input` element (the Text Box),and
3030

3131
## 5. Write the init function
3232

33-
The `init` function should return a sensible initial `Model` value .
33+
The `init` function should return a sensible initial `Model` value.
3434

3535
## 6. Write the main function
3636

37-
The `main` function should call [`Browser.sandbox`][browser-sandbox], passing aa record parameter with the `init`, `update` and `view` functions.
37+
The `main` function should call [`Browser.sandbox`][browser-sandbox], passing a record parameter with the `init`, `update` and `view` functions.
3838

3939
[palindrome-crossword-clues]: https://www.theguardian.com/crosswords/crossword-blog/2012/nov/01/cryptic-crosswords-beginners-palindromes
4040
[browser-sandbox]: https://package.elm-lang.org/packages/elm/browser/latest/Browser#sandbox

0 commit comments

Comments
 (0)