Skip to content

Instantly share code, notes, and snippets.

@bChiquet
Created March 12, 2021 14:17
Show Gist options
  • Save bChiquet/a7ad6941087d2232439b447d6e3589ff to your computer and use it in GitHub Desktop.
Save bChiquet/a7ad6941087d2232439b447d6e3589ff to your computer and use it in GitHub Desktop.
Some Elm Code
module Main exposing (..)
import Browser
import Html exposing (text, div, button, Html)
import Html.Events exposing (onClick)
import Http exposing (get)
import Image exposing (Image)
type alias Model = String
type Msg = ButtonClicked | MsgReceived (Result Http.Error String)
type MyCmd = FetchSelf | NoOperation
pageUrl =
"http://localhost:8000"
getPage = get {url= pageUrl, expect= Http.expectString MsgReceived }
update : Msg -> Model -> (Model, MyCmd)
update msg model = case msg of
ButtonClicked -> ( "Look!", FetchSelf )
MsgReceived result ->
case result of
Err _ -> ("Could not retrieve", NoOperation)
Ok content -> (content, NoOperation)
convert : (model, MyCmd) -> (model, Cmd Msg)
convert cmd =
case cmd of
(model, FetchSelf) -> (model, getPage)
(model, NoOperation) -> (model, Cmd.none)
view : Model -> Html Msg
view model =
div []
[text model, button [onClick ButtonClicked] [text "le bouton"]]
main : Program () Model Msg
main = Browser.element
{ init = \_ -> ( "Hello", Cmd.none )
, view = view
, update = \msg model -> update msg model |> convert
, subscriptions = \_ -> Sub.none
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment