Update part6

This commit is contained in:
Richard Feldman
2016-09-03 15:00:02 -07:00
parent 811da782d2
commit 94f7b65200

View File

@@ -4,7 +4,7 @@ import Html exposing (..)
import Html.App as Html import Html.App as Html
import Html.Attributes exposing (class, target, href, property, defaultValue) import Html.Attributes exposing (class, target, href, property, defaultValue)
import Html.Events exposing (..) import Html.Events exposing (..)
import Json.Decode exposing (Decoder) import Json.Decode exposing (..)
import Json.Decode.Pipeline exposing (..) import Json.Decode.Pipeline exposing (..)
@@ -17,6 +17,10 @@ main =
} }
-- see http://package.elm-lang.org/packages/elm-lang/core/4.0.0/Json-Decode#decodeString
sampleJson : String sampleJson : String
sampleJson = sampleJson =
""" """
@@ -61,11 +65,6 @@ sampleJson =
""" """
responseDecoder : Decoder (List SearchResult)
responseDecoder =
Json.Decode.at [ "items" ] (Json.Decode.list searchResultDecoder)
searchResultDecoder : Decoder SearchResult searchResultDecoder : Decoder SearchResult
searchResultDecoder = searchResultDecoder =
-- See https://developer.github.com/v3/search/#example -- See https://developer.github.com/v3/search/#example
@@ -97,15 +96,28 @@ initialModel =
} }
responseDecoder : Decoder (List SearchResult)
responseDecoder =
decode identity
|> required "items" (list searchResultDecoder)
decodeResults : String -> List SearchResult decodeResults : String -> List SearchResult
decodeResults json = decodeResults json =
-- TODO use Json.Decode.decodeString to translate this into either: case decodeString responseDecoder json of
-- -- TODO add branches to this case-expression which return:
-- * the search results, if decoding succeeded --
-- * an empty list if decoding failed -- * the search results, if decoding succeeded
-- -- * an empty list if decoding failed
-- see http://package.elm-lang.org/packages/elm-lang/core/4.0.0/Json-Decode#decodeString --
[] -- see http://package.elm-lang.org/packages/elm-lang/core/4.0.0/Json-Decode#decodeString
--
-- HINT: decodeString returns a Result which is one of the following:
--
-- Ok (List SearchResult)
-- Err String
_ ->
[]
view : Model -> Html Msg view : Model -> Html Msg