From 82f5761c3717c48cfc9941df4f4a3bdc61098813 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 27 Mar 2016 07:05:32 -0700 Subject: [PATCH] Add a bit on lazy --- stages/10/Component/ElmHub.elm | 25 +++++++++++++++++++++++-- stages/9/ElmHub.elm | 19 ++++++++++++++++++- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/stages/10/Component/ElmHub.elm b/stages/10/Component/ElmHub.elm index edc0207..e825e6d 100644 --- a/stages/10/Component/ElmHub.elm +++ b/stages/10/Component/ElmHub.elm @@ -3,6 +3,7 @@ module Component.ElmHub (..) where import Html exposing (..) import Html.Attributes exposing (..) import Html.Events exposing (..) +import Html.Lazy exposing (..) import Http import Task exposing (Task) import Effects exposing (Effects) @@ -69,10 +70,30 @@ view address model = , button [ class "search-button", onClick address Search ] [ text "Search" ] , ul [ class "results" ] - (List.map (viewSearchResult address) model.results) + (viewSearchResults address model.results) ] +viewSearchResults : Address Action -> List Component.SearchResult.Model -> List Html +viewSearchResults address results = + results + |> filterResults + |> List.map (lazy2 viewSearchResult address) + + +filterResults : List Component.SearchResult.Model -> List Component.SearchResult.Model +filterResults results = + case results of + [] -> + [] + + first :: rest -> + if first.stars > 0 then + first :: (filterResults rest) + else + filterResults rest + + onInput address wrap = on "input" targetValue (\val -> Signal.message address (wrap val)) @@ -85,7 +106,7 @@ viewSearchResult : Address Action -> Component.SearchResult.Model -> Html viewSearchResult address result = Component.SearchResult.view (Signal.forwardTo address (UpdateSearchResult result.id)) - result + (Debug.log "rendering result..." result) type Action diff --git a/stages/9/ElmHub.elm b/stages/9/ElmHub.elm index d5eb24b..bab5aa0 100644 --- a/stages/9/ElmHub.elm +++ b/stages/9/ElmHub.elm @@ -3,6 +3,7 @@ module ElmHub (..) where import Html exposing (..) import Html.Attributes exposing (..) import Html.Events exposing (..) +import Html.Lazy exposing (..) import Http import Task exposing (Task) import Effects exposing (Effects) @@ -88,9 +89,17 @@ viewSearchResults address results = results |> Dict.values |> List.sortBy (.stars >> negate) + |> filterResults |> List.map (viewSearchResult address) +filterResults : List SearchResult -> List SearchResult +filterResults results = + -- TODO filter out repos with 0 stars + -- using a case-expression rather than List.filter + [] + + onInput address wrap = on "input" targetValue (\val -> Signal.message address (wrap val)) @@ -105,7 +114,15 @@ viewSearchResult address result = [] [ span [ class "star-count" ] [ text (toString result.stars) ] , a - [ href ("https://github.com/" ++ result.name), target "_blank" ] + [ href + ("https://github.com/" + ++ (Debug.log "Viewing" result.name) + {- TODO we should no longer see this + console output when typing in the search box! + -} + ) + , target "_blank" + ] [ text result.name ] , button [ class "hide-result", onClick address (DeleteById result.id) ]