Reorganize part9 and part10 a bit.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
module ElmHub exposing (..)
|
port module ElmHub exposing (..)
|
||||||
|
|
||||||
import Html exposing (..)
|
import Html exposing (..)
|
||||||
import Html.Attributes exposing (class, target, href, defaultValue, type', checked, placeholder, value)
|
import Html.Attributes exposing (class, target, href, defaultValue, type', checked, placeholder, value)
|
||||||
@@ -60,6 +60,16 @@ initialModel =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
init : ( Model, Cmd Msg )
|
||||||
|
init =
|
||||||
|
( initialModel, githubSearch (getQueryString initialModel) )
|
||||||
|
|
||||||
|
|
||||||
|
subscriptions : Model -> Sub Msg
|
||||||
|
subscriptions _ =
|
||||||
|
githubResponse decodeResponse
|
||||||
|
|
||||||
|
|
||||||
type Msg
|
type Msg
|
||||||
= Search
|
= Search
|
||||||
| Options OptionsMsg
|
| Options OptionsMsg
|
||||||
@@ -70,14 +80,14 @@ 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
|
||||||
Options optionsMsg ->
|
Options optionsMsg ->
|
||||||
( { model | options = updateOptions optionsMsg model.options }, Cmd.none )
|
( { model | options = updateOptions optionsMsg model.options }, Cmd.none )
|
||||||
|
|
||||||
Search ->
|
Search ->
|
||||||
( model, searchFeed (getQueryString model) )
|
( model, githubSearch (getQueryString model) )
|
||||||
|
|
||||||
SetQuery query ->
|
SetQuery query ->
|
||||||
( { model | query = query }, Cmd.none )
|
( { model | query = query }, Cmd.none )
|
||||||
@@ -213,6 +223,22 @@ onChange toMsg =
|
|||||||
on "change" (Json.Decode.map toMsg Html.Events.targetValue)
|
on "change" (Json.Decode.map toMsg Html.Events.targetValue)
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
{-| NOTE: The following is not part of the exercise, but is food for thought if
|
{-| NOTE: The following is not part of the exercise, but is food for thought if
|
||||||
you have extra time.
|
you have extra time.
|
||||||
|
|
||||||
|
|||||||
@@ -1,31 +1,14 @@
|
|||||||
port module Main exposing (..)
|
module Main exposing (main)
|
||||||
|
|
||||||
import ElmHub exposing (..)
|
import ElmHub
|
||||||
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 = ElmHub.view
|
||||||
, update = update githubSearch
|
, update = ElmHub.update
|
||||||
, init = ( initialModel, githubSearch (getQueryString initialModel) )
|
, init = ElmHub.init
|
||||||
, subscriptions = \_ -> githubResponse decodeResponse
|
, subscriptions = ElmHub.subscriptions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|||||||
@@ -53,6 +53,16 @@ initialModel =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
init : ( Model, Cmd Msg )
|
||||||
|
init =
|
||||||
|
( initialModel, githubSearch (getQueryString initialModel.query) )
|
||||||
|
|
||||||
|
|
||||||
|
subscriptions : Model -> Sub Msg
|
||||||
|
subscriptions _ =
|
||||||
|
githubResponse decodeResponse
|
||||||
|
|
||||||
|
|
||||||
view : Model -> Html Msg
|
view : Model -> Html Msg
|
||||||
view model =
|
view model =
|
||||||
div [ class "content" ]
|
div [ class "content" ]
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
module Main exposing (..)
|
module Main exposing (main)
|
||||||
|
|
||||||
import ElmHub exposing (..)
|
import ElmHub
|
||||||
import Html.App as Html
|
import Html.App as Html
|
||||||
|
|
||||||
|
|
||||||
main : Program Never
|
main : Program Never
|
||||||
main =
|
main =
|
||||||
Html.program
|
Html.program
|
||||||
{ view = view
|
{ view = ElmHub.view
|
||||||
, update = update
|
, update = ElmHub.update
|
||||||
, init = ( initialModel, githubSearch (getQueryString initialModel.query) )
|
, init = ElmHub.init
|
||||||
, subscriptions = \_ -> githubResponse decodeResponse
|
, subscriptions = ElmHub.subscriptions
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user