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

Make hello world message #33

Closed
mckelveygreg opened this issue Apr 23, 2019 · 2 comments
Closed

Make hello world message #33

mckelveygreg opened this issue Apr 23, 2019 · 2 comments
Assignees

Comments

@mckelveygreg
Copy link
Collaborator

Back:
@daved, What does the hello world message look like to an outsider?

Front:
@nqthqn, what needs to be set up in Elm if we are to communicate with @daved 's hello world message branch?

@nqthqn
Copy link

nqthqn commented Apr 25, 2019

You would make a command and then ask Elm to run it for you -

import Http

type Msg
  = GotHello (Result Http.Error String)

getHello : Cmd Msg
getHello =
  Http.get
    { url = "/hello"
    , expect = Http.expectString GotHello
    }

Note - not sure on the url and instead of String you would use a generated type alias and decoder from an Entity/ module.

To run the command,

init = 
    (model, getHello)

To react to the response from the command:

update msg model =
    case msg of
        GotHello (Ok response) ->
            ({ model | hello = response }, Cmd.none)

        GotHello (Err _) ->
            ({ model | hello = "uh oh" }, Cmd.none)

You could of course pattern match on the Http.Error and give the user more than just "uh oh".

@daved
Copy link
Member

daved commented Nov 27, 2019

Closed in favor of #76

@daved daved closed this as completed Nov 27, 2019
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

3 participants