Reorganize part9

This commit is contained in:
Richard Feldman
2016-09-06 20:21:14 -07:00
parent 3456b14f7e
commit 9878f5d993
2 changed files with 22 additions and 23 deletions

View File

@@ -1,4 +1,4 @@
module ElmHub exposing (..) port module ElmHub exposing (..)
import Html exposing (..) import Html exposing (..)
import Html.Attributes exposing (class, target, href, property, defaultValue) import Html.Attributes exposing (class, target, href, property, defaultValue)
@@ -97,11 +97,11 @@ type Msg
| DoNothing | DoNothing
update : (String -> Cmd Msg) -> Msg -> Model -> ( Model, Cmd Msg ) update : Msg -> Model -> ( Model, Cmd Msg )
update searchFeed msg model = update msg model =
case msg of case msg of
Search -> Search ->
( model, searchFeed (getQueryString model.query) ) ( model, githubSearch (getQueryString model.query) )
SetQuery query -> SetQuery query ->
( { model | query = query }, Cmd.none ) ( { model | query = query }, Cmd.none )
@@ -135,3 +135,19 @@ decodeGithubResponse value =
Err err -> Err err ->
HandleSearchError (Just err) HandleSearchError (Just err)
decodeResponse : Json.Decode.Value -> Msg
decodeResponse json =
case Json.Decode.decodeValue responseDecoder json of
Err err ->
HandleSearchError (Just err)
Ok results ->
HandleSearchResponse results
port githubSearch : String -> Cmd msg
port githubResponse : (Json.Decode.Value -> msg) -> Sub msg

View File

@@ -1,31 +1,14 @@
port module Main exposing (..) module Main exposing (..)
import ElmHub exposing (..) import ElmHub exposing (..)
import Html.App as Html import Html.App as Html
import Json.Decode
main : Program Never main : Program Never
main = main =
Html.program Html.program
{ view = view { view = view
, update = update githubSearch , update = update
, init = ( initialModel, githubSearch (getQueryString initialModel.query) ) , init = ( initialModel, githubSearch (getQueryString initialModel.query) )
, subscriptions = \_ -> githubResponse decodeResponse , subscriptions = \_ -> githubResponse decodeResponse
} }
decodeResponse : Json.Decode.Value -> Msg
decodeResponse json =
case Json.Decode.decodeValue responseDecoder json of
Err err ->
HandleSearchError (Just err)
Ok results ->
HandleSearchResponse results
port githubSearch : String -> Cmd msg
port githubResponse : (Json.Decode.Value -> msg) -> Sub msg