Skip to content

Instantly share code, notes, and snippets.

@martimatix
Created June 26, 2016 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martimatix/8f91db81f6643bcf69040910fcff866b to your computer and use it in GitHub Desktop.
Save martimatix/8f91db81f6643bcf69040910fcff866b to your computer and use it in GitHub Desktop.
movie_poster_finder
import Html exposing (..)
import Html.App as Html
import Html.Attributes exposing (..)
import Html.Events exposing (..)
main =
Html.program
{ init = init
, view = view
, update = update
, subscriptions = subscriptions
}
-- MODEL
type alias Model =
{ searchString : String
, title: String
, posterUrl : String
}
init : (Model, Cmd Msg)
init =
( Model "Frozen" "" "waiting.gif"
, Cmd.none
)
-- UPDATE
type Msg
= ChangeMovieTitle String
update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
case msg of
ChangeMovieTitle newSearchString ->
{ model | title = newSearchString } ! []
-- VIEW
view : Model -> Html Msg
view model =
div []
[ input [ placeholder "enter a movie title"
, autofocus True
, onInput ChangeMovieTitle
] []
, button [] [ text "Get poster!" ]
, br [] []
, h1 [] [ text model.title ]
, img [src model.posterUrl] []
]
-- SUBSCRIPTIONS
subscriptions : Model -> Sub Msg
subscriptions model =
Sub.none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment