From 9be07b4f020908dd5f8f6c2701a49a429ec2f0c3 Mon Sep 17 00:00:00 2001 From: Evan Czaplicki Date: Wed, 20 Jul 2016 16:57:24 -0700 Subject: [PATCH] Make changes recommend by @rtfeldman --- examples/1-presidents.elm | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/examples/1-presidents.elm b/examples/1-presidents.elm index 5f36979..b62bb67 100644 --- a/examples/1-presidents.elm +++ b/examples/1-presidents.elm @@ -1,6 +1,6 @@ import Html exposing (Html, div, h1, input, text) import Html.App as App -import Html.Attributes exposing (placeholder, value) +import Html.Attributes exposing (placeholder) import Html.Events exposing (onInput) import String import Table @@ -44,19 +44,19 @@ init people = type Msg - = UpdateQuery String - | UpdateTableState Table.State + = SetQuery String + | SetTableState Table.State update : Msg -> Model -> ( Model, Cmd Msg ) update msg model = case msg of - UpdateQuery newQuery -> - ( { model | query = String.toLower newQuery } + SetQuery newQuery -> + ( { model | query = newQuery } , Cmd.none ) - UpdateTableState newState -> + SetTableState newState -> ( { model | tableState = newState } , Cmd.none ) @@ -69,17 +69,15 @@ update msg model = view : Model -> Html Msg view { people, tableState, query } = let + lowerQuery = + String.toLower query + acceptablePeople = - List.filter (String.contains query << String.toLower << .name) people + List.filter (String.contains lowerQuery << String.toLower << .name) people in div [] [ h1 [] [ text "Birthplaces of U.S. Presidents" ] - , input - [ value query - , placeholder "Search by Name" - , onInput UpdateQuery - ] - [] + , input [ placeholder "Search by Name", onInput SetQuery ] [] , Table.view config tableState acceptablePeople ] @@ -88,7 +86,7 @@ config : Table.Config Person Msg config = Table.config { toId = .name - , toMsg = UpdateTableState + , toMsg = SetTableState , columns = [ Table.stringColumn "Name" .name , Table.intColumn "Year" .year