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

Don't use catch-all in main update - not a recommended way to code in Elm #81

Open
amilner42 opened this issue Aug 6, 2019 · 0 comments

Comments

@amilner42
Copy link

Very easy fix to make the code more elm-like (aka the compiler more helpful).

You currently do

( _, _ ) ->
            -- Disregard messages that arrived for the wrong page.
            ( model, Cmd.none )

When someone adds a new page though, it will fall into this case, which is clearly not what we want. We want the compiler to force us to add it. To achieve this, it's better to instead do:

( GotEditorMsg subMsg, Editor slug editor ) ->
    Editor.update subMsg editor
        |> updateWith (Editor slug) GotEditorMsg model

( GotEditorMsg _, _ ) ->
    (model, Cmd.none)

( GotArticleMsg subMsg, Article article ) ->
     Article.update subMsg article
        |> updateWith Article GotArticleMsg model

( GotArticleMsg _, _) ->
    (model, Cmd.none)

etc.

It is more verbose but definitely more elm-like. Now if someone adds GotXMsg the compiler will tell them that they are missing a case, go elm 😃 I think it's also valuable to set an example given this repo is used as a reference for how to code in Elm by many people new to Elm.

amilner42 added a commit to amilner42/viva-doc that referenced this issue Aug 6, 2019
…all-case at the bottom

- Created an issue in the main elm spa to do the same: rtfeldman/elm-spa-example#81
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant