Skip to content

Commit

Permalink
Introduce Html.program
Browse files Browse the repository at this point in the history
This is a more complex program that allows interaction with the outside
world with commands and subscriptions. Following the compiler errors,
we update signatures and return values to match what is required from
`Html.program`.
  • Loading branch information
JoelQ committed Jul 5, 2017
1 parent a4c86fa commit c0e9979
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import Html.Events exposing (onClick, onInput)


main =
Html.beginnerProgram
{ model = initialModel
Html.program
{ init = ( initialModel, Cmd.none )
, view = view
, update = update
, subscriptions = (\_ -> Sub.none)
}


Expand Down Expand Up @@ -102,17 +103,19 @@ type Msg
| SearchInput String


update : Msg -> Model -> Model
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
OpenSelect ->
{ model | state = Open }
( { model | state = Open }, Cmd.none )

CloseSelect ->
{ model | state = Closed }
( { model | state = Closed }, Cmd.none )

ItemSelected value ->
{ model | selected = Just value, state = Closed, query = "" }
( { model | selected = Just value, state = Closed, query = "" }
, Cmd.none
)

SearchInput query ->
{ model | query = query }
( { model | query = query }, Cmd.none )

0 comments on commit c0e9979

Please sign in to comment.