Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add subscription information to keyboard example #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions notes/keyboard.md
Original file line number Diff line number Diff line change
@@ -87,4 +87,18 @@ toDirection string =

By converting to a specialized `Direction` type, the compiler can guarantee that you never forget to handle one of the valid inputs. If it was a `String`, new code could have typos or missing branches that would be hard to find.

Based on this snippet, this is how the `subscription` and `msg` parts of the code could look like :

```elm
type Msg
= KeyPressed Direction

...

subscriptions : Model -> Sub Msg
subscriptions _ =
onKeyDown (Json.Decode.map KeyPressed keyDecoder)
```


Hope that helps you write a decoder that works for your scenario!