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.Attributes exposing (class, target, href, property, defaultValue)
import Html.Events exposing (..)
import Json.Decode exposing (Decoder)
import Json.Decode 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 =
"""
@@ -61,11 +65,6 @@ sampleJson =
"""
responseDecoder : Decoder (List SearchResult)
responseDecoder =
Json.Decode.at [ "items" ] (Json.Decode.list searchResultDecoder)
searchResultDecoder : Decoder SearchResult
searchResultDecoder =
-- See https://developer.github.com/v3/search/#example
@@ -97,14 +96,27 @@ initialModel =
}
responseDecoder : Decoder (List SearchResult)
responseDecoder =
decode identity
|> required "items" (list searchResultDecoder)
decodeResults : String -> List SearchResult
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
--
-- 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
_ ->
[]