Skip to content

Instantly share code, notes, and snippets.

View arecvlohe's full-sized avatar
🚫
End ASF Mascotry / Drop ICE

Adam Recvlohe arecvlohe

🚫
End ASF Mascotry / Drop ICE
View GitHub Profile
subscriptions : Model -> Sub Msg
subscriptions model =
Sub.none
main : Program Never Model Msg
main =
Html.program
{ init = init
, update = update
, subscriptions = subscriptions
, view = view
}
view: Model -> Html Msg
view model =
div []
[ div [] [ text model.author ]
, div [] [ text model.quote ]
, button [ onClick FetchQuote ] [ text "Fetch new quote" ]
]
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
FetchQuote ->
( model, Random.generate NewQuote (Random.int 0 3) )
NewQuote index ->
( withDefault defaultQuote (getAt index quotes), Cmd.none )
NoOp ->
( model, Cmd.none )
type Msg
= NoOp
| FetchQuote
| NewQuote Int
quotes : List Model
quotes =
[ { author = "Victoria Justice", quote = "It's nice to just embrace the natural beauty within you." }
, { author = "Moises Arias", quote = "It is nice finding that place where you can just go and relax." }
, { author = "Yogi Berra", quote = "It ain't over till it's over" }
, { author = "Albert Einstein", quote = "Look deep into nature, and then you will understand everything better." }
]
module Main exposing (..)
import Html exposing (Html, text, div)
-- MODEL
type alias Model =
{ author : String
, quote : String
}
main : Program Never Model Msg
main =
Html.beginnerProgram
{ model = model
, update = update
, view = view
}
type Msg
= NoOp
update : Msg -> Model -> Model
update msg model =
case msg of
NoOp ->
model
view : Model -> Html Msg
view model =
div []
[ div [] [ text model.quote ]
, div [] [ text model.author ]
]