From 533638108d181111e48c0f4dc6f5ed4bf0125954 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 19 Aug 2016 03:49:41 -0700 Subject: [PATCH] Remove ResultId --- part10/ElmHub.elm | 10 +++++----- part10/SearchResult.elm | 4 ---- part11/ElmHub.elm | 10 +++++----- part11/SearchResult.elm | 10 +++------- part12/ElmHub.elm | 10 +++++----- part12/SearchResult.elm | 10 +++------- part5/Main.elm | 16 ++-------------- part6/Main.elm | 8 ++------ part7/ElmHub.elm | 8 ++------ part8/ElmHub.elm | 8 ++------ part9/ElmHub.elm | 8 ++------ 11 files changed, 31 insertions(+), 71 deletions(-) diff --git a/part10/ElmHub.elm b/part10/ElmHub.elm index be297cf..f2381cf 100644 --- a/part10/ElmHub.elm +++ b/part10/ElmHub.elm @@ -9,7 +9,7 @@ import Auth import Task exposing (Task) import Json.Decode exposing (Decoder) import Dict exposing (Dict) -import SearchResult exposing (ResultId) +import SearchResult searchFeed : String -> Cmd Msg @@ -32,7 +32,7 @@ responseDecoder = type alias Model = { query : String - , results : Dict ResultId SearchResult.Model + , results : Dict Int SearchResult.Model , errorMessage : Maybe String } @@ -69,7 +69,7 @@ viewErrorMessage errorMessage = text "" -viewSearchResults : Dict ResultId SearchResult.Model -> List (Html Msg) +viewSearchResults : Dict Int SearchResult.Model -> List (Html Msg) viewSearchResults results = results |> Dict.values @@ -89,7 +89,7 @@ viewSearchResult result = type Msg = Search | SetQuery String - | UpdateSearchResult ResultId SearchResult.Msg + | UpdateSearchResult Int SearchResult.Msg | HandleSearchResponse (List SearchResult.Model) | HandleSearchError Http.Error @@ -113,7 +113,7 @@ update msg model = HandleSearchResponse results -> let - resultsById : Dict ResultId SearchResult.Model + resultsById : Dict Int SearchResult.Model resultsById = results |> List.map (\result -> ( result.id, result )) diff --git a/part10/SearchResult.elm b/part10/SearchResult.elm index fa7c873..30e7972 100644 --- a/part10/SearchResult.elm +++ b/part10/SearchResult.elm @@ -15,10 +15,6 @@ type alias Model = } -type alias ResultId = - Int - - type Msg = Expand | Collapse diff --git a/part11/ElmHub.elm b/part11/ElmHub.elm index b3dc5a2..f6075ab 100644 --- a/part11/ElmHub.elm +++ b/part11/ElmHub.elm @@ -9,7 +9,7 @@ import Auth import Task exposing (Task) import Json.Decode exposing (Decoder) import Dict exposing (Dict) -import SearchResult exposing (ResultId) +import SearchResult searchFeed : String -> Cmd Msg @@ -32,7 +32,7 @@ responseDecoder = type alias Model = { query : String - , results : Dict ResultId SearchResult.Model + , results : Dict Int SearchResult.Model , errorMessage : Maybe String } @@ -69,7 +69,7 @@ viewErrorMessage errorMessage = text "" -viewSearchResults : Dict ResultId SearchResult.Model -> List (Html Msg) +viewSearchResults : Dict Int SearchResult.Model -> List (Html Msg) viewSearchResults results = results |> Dict.values @@ -95,7 +95,7 @@ viewSearchResult result = type Msg = Search | SetQuery String - | UpdateSearchResult ResultId SearchResult.Msg + | UpdateSearchResult Int SearchResult.Msg | HandleSearchResponse (List SearchResult.Model) | HandleSearchError Http.Error @@ -119,7 +119,7 @@ update msg model = HandleSearchResponse results -> let - resultsById : Dict ResultId SearchResult.Model + resultsById : Dict Int SearchResult.Model resultsById = results |> List.map (\result -> ( result.id, result )) diff --git a/part11/SearchResult.elm b/part11/SearchResult.elm index a251fb4..36f58df 100644 --- a/part11/SearchResult.elm +++ b/part11/SearchResult.elm @@ -15,10 +15,6 @@ type alias Model = } -type alias ResultId = - Int - - type Msg = Expand | Collapse @@ -45,8 +41,8 @@ update msg model = view : Model -> Html Msg view model = - li [] - <| if model.expanded then + li [] <| + if model.expanded then [ span [ class "star-count" ] [ text (toString model.stars) ] , a [ href @@ -61,7 +57,7 @@ view model = , button [ class "hide-result", onClick Collapse ] [ text "X" ] ] - else + else [ button [ class "expand-result", onClick Expand ] [ text "Show" ] ] diff --git a/part12/ElmHub.elm b/part12/ElmHub.elm index 4396204..f8a2ff1 100644 --- a/part12/ElmHub.elm +++ b/part12/ElmHub.elm @@ -9,7 +9,7 @@ import Auth import Task exposing (Task) import Json.Decode exposing (Decoder) import Dict exposing (Dict) -import SearchResult exposing (ResultId) +import SearchResult searchFeed : String -> Cmd Msg @@ -32,7 +32,7 @@ responseDecoder = type alias Model = { query : String - , results : Dict ResultId SearchResult.Model + , results : Dict Int SearchResult.Model , errorMessage : Maybe String } @@ -69,7 +69,7 @@ viewErrorMessage errorMessage = text "" -viewSearchResults : Dict ResultId SearchResult.Model -> List (Html Msg) +viewSearchResults : Dict Int SearchResult.Model -> List (Html Msg) viewSearchResults results = results |> Dict.values @@ -87,7 +87,7 @@ viewSearchResult result = type Msg = Search | SetQuery String - | UpdateSearchResult ResultId SearchResult.Msg + | UpdateSearchResult Int SearchResult.Msg | HandleSearchResponse (List SearchResult.Model) | HandleSearchError Http.Error @@ -111,7 +111,7 @@ update msg model = HandleSearchResponse results -> let - resultsById : Dict ResultId SearchResult.Model + resultsById : Dict Int SearchResult.Model resultsById = results |> List.map (\result -> ( result.id, result )) diff --git a/part12/SearchResult.elm b/part12/SearchResult.elm index d4ff41d..a72972d 100644 --- a/part12/SearchResult.elm +++ b/part12/SearchResult.elm @@ -15,10 +15,6 @@ type alias Model = } -type alias ResultId = - Int - - type Msg = Expand | Collapse @@ -45,15 +41,15 @@ update msg model = view : Model -> Html Msg view model = - li [] - <| if model.expanded then + li [] <| + if model.expanded then [ span [ class "star-count" ] [ text (toString model.stars) ] , a [ href ("https://github.com/" ++ model.name), target "_blank" ] [ text model.name ] , button [ class "hide-result", onClick Collapse ] [ text "X" ] ] - else + else [ button [ class "expand-result", onClick Expand ] [ text "Show" ] ] diff --git a/part5/Main.elm b/part5/Main.elm index 5ecb67d..4035ce5 100644 --- a/part5/Main.elm +++ b/part5/Main.elm @@ -84,16 +84,12 @@ type alias Model = type alias SearchResult = - { id : ResultId + { id : Int , name : String , stars : Int } -type alias ResultId = - Int - - initialModel : Model initialModel = { query = "tutorial" @@ -139,8 +135,7 @@ viewSearchResult result = type Msg = SetQuery String - | DeleteById ResultId - | SetResults (List SearchResult) + | DeleteById Int update : Msg -> Model -> Model @@ -149,13 +144,6 @@ update msg model = SetQuery query -> { model | query = query } - SetResults results -> - let - newModel = - { model | results = results } - in - newModel - DeleteById idToHide -> let newResults = diff --git a/part6/Main.elm b/part6/Main.elm index 563547d..3356fca 100644 --- a/part6/Main.elm +++ b/part6/Main.elm @@ -67,16 +67,12 @@ type alias Model = type alias SearchResult = - { id : ResultId + { id : Int , name : String , stars : Int } -type alias ResultId = - Int - - initialModel : Model initialModel = { query = "tutorial" @@ -123,7 +119,7 @@ viewSearchResult result = type Msg = Search | SetQuery String - | DeleteById ResultId + | DeleteById Int | HandleSearchResponse (List SearchResult) | HandleSearchError Http.Error diff --git a/part7/ElmHub.elm b/part7/ElmHub.elm index 8cf2189..7c37af4 100644 --- a/part7/ElmHub.elm +++ b/part7/ElmHub.elm @@ -39,16 +39,12 @@ type alias Model = type alias SearchResult = - { id : ResultId + { id : Int , name : String , stars : Int } -type alias ResultId = - Int - - initialModel : Model initialModel = { query = "tutorial" @@ -95,7 +91,7 @@ viewSearchResult result = type Msg = Search | SetQuery String - | DeleteById ResultId + | DeleteById Int | HandleSearchResponse (List SearchResult) | HandleSearchError (Maybe String) diff --git a/part8/ElmHub.elm b/part8/ElmHub.elm index 9e9a821..6a47dcc 100644 --- a/part8/ElmHub.elm +++ b/part8/ElmHub.elm @@ -39,16 +39,12 @@ type alias Model = type alias SearchResult = - { id : ResultId + { id : Int , name : String , stars : Int } -type alias ResultId = - Int - - initialModel : Model initialModel = { query = "tutorial" @@ -95,7 +91,7 @@ viewSearchResult result = type Msg = Search | SetQuery String - | DeleteById ResultId + | DeleteById Int | HandleSearchResponse (List SearchResult) | HandleSearchError (Maybe String) | DoNothing diff --git a/part9/ElmHub.elm b/part9/ElmHub.elm index 96fa664..0345523 100644 --- a/part9/ElmHub.elm +++ b/part9/ElmHub.elm @@ -45,16 +45,12 @@ type alias Model = type alias SearchResult = - { id : ResultId + { id : Int , name : String , stars : Int } -type alias ResultId = - Int - - initialModel : Model initialModel = { query = "tutorial" @@ -96,7 +92,7 @@ viewSearchResult result = type Msg = Search | SetQuery String - | DeleteById ResultId + | DeleteById Int | HandleSearchResponse (List SearchResult) | HandleSearchError Http.Error | DoNothing