Use performAction instead of Task.map and Task.onError directly

This commit is contained in:
Richard Feldman
2016-04-01 10:39:55 -07:00
parent 8ba9cde9ef
commit 05f1716c43

View File

@@ -40,12 +40,8 @@ searchFeed query =
"https://api.github.com/search/repositories?q=" "https://api.github.com/search/repositories?q="
++ query ++ query
++ "+language:elm&sort=stars&order=desc" ++ "+language:elm&sort=stars&order=desc"
task =
Http.get responseDecoder url
|> Task.map SetResults
in in
Task.onError task (\_ -> Task.succeed (SetResults [])) performAction SetResults (\_ -> SetResults []) (Http.get responseDecoder url)
responseDecoder : Decoder (List SearchResult) responseDecoder : Decoder (List SearchResult)
@@ -63,6 +59,15 @@ searchResultDecoder =
("TODO what field goes here?" := Json.Decode.int) ("TODO what field goes here?" := Json.Decode.int)
performAction : (a -> b) -> (y -> b) -> Task y a -> Task x b
performAction successToAction errorToAction task =
let
successTask =
Task.map successToAction task
in
Task.onError successTask (\err -> Task.succeed (errorToAction err))
type alias Model = type alias Model =
{ query : String { query : String
, results : List SearchResult , results : List SearchResult