Update part8 and part9
This commit is contained in:
@@ -5,6 +5,9 @@ import ElmHub exposing (..)
|
||||
import Effects exposing (Effects)
|
||||
import Task exposing (Task)
|
||||
import Html exposing (Html)
|
||||
import Signal
|
||||
import Json.Encode
|
||||
import Json.Decode
|
||||
|
||||
|
||||
main : Signal Html
|
||||
@@ -16,12 +19,40 @@ app : StartApp.App Model
|
||||
app =
|
||||
StartApp.start
|
||||
{ view = view
|
||||
, update = update
|
||||
, init = ( initialModel, Effects.task (searchFeed initialModel.query) )
|
||||
, inputs = []
|
||||
, update = update search.address
|
||||
, init = ( initialModel, searchFeed search.address initialModel.query )
|
||||
, inputs = [ responseActions ]
|
||||
}
|
||||
|
||||
|
||||
port tasks : Signal (Task Effects.Never ())
|
||||
port tasks =
|
||||
app.tasks
|
||||
|
||||
|
||||
search : Signal.Mailbox String
|
||||
search =
|
||||
Signal.mailbox ""
|
||||
|
||||
|
||||
port githubSearch : Signal String
|
||||
port githubSearch =
|
||||
search.signal
|
||||
|
||||
|
||||
responseActions : Signal Action
|
||||
responseActions =
|
||||
Signal.map decodeGithubResponse githubResponse
|
||||
|
||||
|
||||
decodeGithubResponse : Json.Encode.Value -> Action
|
||||
decodeGithubResponse value =
|
||||
case Json.Decode.decodeValue responseDecoder value of
|
||||
Ok results ->
|
||||
SetResults results
|
||||
|
||||
Err message ->
|
||||
SetErrorMessage (Just message)
|
||||
|
||||
|
||||
port githubResponse : Signal Json.Encode.Value
|
||||
|
||||
Reference in New Issue
Block a user