Add a bit on lazy

This commit is contained in:
Richard Feldman
2016-03-27 07:05:32 -07:00
parent 809b5b1adc
commit 82f5761c37
2 changed files with 41 additions and 3 deletions

View File

@@ -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

View File

@@ -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) ]