Skip to content

Instantly share code, notes, and snippets.

@jlleblanc
Created October 24, 2017 03:06
Show Gist options
  • Save jlleblanc/9307375ac3945ef9b77d2e70a8e77194 to your computer and use it in GitHub Desktop.
Save jlleblanc/9307375ac3945ef9b77d2e70a8e77194 to your computer and use it in GitHub Desktop.
module Main exposing (..)
import Html exposing (Html, text, div, img, button)
import Html.Events exposing (..)
import Http
import Json.Decode as Decode
type Msg
= TruffleFeed (Result Http.Error String)
| LoadTruffles
getTruffles : String -> Cmd Msg
getTruffles url =
let
request =
Http.get url decodeTruffles
in
Http.send TruffleFeed request
decodeTruffles : Decode.Decoder String
decodeTruffles =
Decode.string
---- MODEL ----
type alias Model =
{}
init : ( Model, Cmd Msg )
init =
( {}, Cmd.none )
---- UPDATE ----
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
LoadTruffles ->
( model, getTruffles "/feed.json" )
TruffleFeed (Ok _) ->
( model, Cmd.none )
TruffleFeed (Err _) ->
( model, Cmd.none )
---- VIEW ----
view : Model -> Html Msg
view model =
div []
[ button [ onClick LoadTruffles ] [ text "Load Truffles!" ]
]
---- PROGRAM ----
main : Program Never Model Msg
main =
Html.program
{ view = view
, init = init
, update = update
, subscriptions = always Sub.none
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment