Skip to content

Instantly share code, notes, and snippets.

@sareiodata
Created November 6, 2019 13:21
Show Gist options
  • Save sareiodata/d0948bac308400eb7d90612b6cf1539c to your computer and use it in GitHub Desktop.
Save sareiodata/d0948bac308400eb7d90612b6cf1539c to your computer and use it in GitHub Desktop.
Questions about Elm language
https://guide.elm-lang.org/effects/http.html
main =
Browser.element
{ init = init
, update = update
, subscriptions = subscriptions
, view = view
}
Questions about:
init = init
First init: a variable expected by Browser.element function?
Second init: a function declared in my program?
etc. for update, subscription, view.
---------------------------------------------------------------
init : () -> (Model, Cmd Msg)
init _ =
( Loading
, Http.get
{ url = "https://elm-lang.org/assets/public-opinion.txt"
, expect = Http.expectString GotText
}
)
init : () -> (Model, Cmd Msg)
Is sort of:
function init() {
....
return (Model, Cmd Msg)
}
What is Cmd Msg . I'm returning a Model AND Cmd Msg
However, Cmd Msg represents two variables?
Why not init : () -> (Model, Cmd, Msg)
How are the two different?
-------------------------------------------------------------
update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
case msg of
GotText result ->
case result of
Ok fullText ->
(Success fullText, Cmd.none)
Err _ ->
(Failure, Cmd.none)
How is (Success fullText, Cmd.none) the same as (Model, Cmd Msg) ?
Specifically how is Cmd.none the same as Cmd Msg
Success fullText is what Model returns so that's clear, but Cmd.none? What is Cmd.none :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment