This commit is contained in:
Richard Feldman
2016-03-06 08:17:43 -08:00
parent f6c5b5dc02
commit 7c655aaebc
5 changed files with 18 additions and 65 deletions

View File

@@ -8,7 +8,6 @@
], ],
"exposed-modules": [], "exposed-modules": [],
"dependencies": { "dependencies": {
"NoRedInk/elm-check": "3.0.0 <= v < 4.0.0",
"elm-lang/core": "3.0.0 <= v < 4.0.0", "elm-lang/core": "3.0.0 <= v < 4.0.0",
"evancz/elm-effects": "2.0.0 <= v < 3.0.0", "evancz/elm-effects": "2.0.0 <= v < 3.0.0",
"evancz/elm-html": "4.0.0 <= v < 5.0.0", "evancz/elm-html": "4.0.0 <= v < 5.0.0",

File diff suppressed because one or more lines are too long

View File

@@ -4,31 +4,22 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>ElmHub</title> <title>ElmHub</title>
<script type="text/javascript" src="github.js"></script>
<script type="text/javascript" src="elm.js"></script> <script type="text/javascript" src="elm.js"></script>
<!-- Uncomment the below line to enable elm-reactor support. -->
<!-- <script type="text/javascript" src="/_reactor/debug.js"></script> -->
<link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style.css">
</head> </head>
<body> <body>
<div id="elm-landing-pad"></div>
</body> </body>
<script type="text/javascript"> <script type="text/javascript">
var github = new Github(); var app = Elm.fullscreen(Elm.Main, {});
var app = Elm.embed(
Elm.Main,
document.getElementById("elm-landing-pad"),
{githubResponse: []});
app.ports.githubSearch.subscribe(function(query) { // Uncomment this line and comment out the above to enable elm-reactor support.
console.log("Searching for", query); // var app = Elm.fullscreenDebug("ElmHub", "Main.elm");
var search = github.getSearch(query);
search.repositories({}, function (err, repositories) {
console.log("Got response", repositories);
app.ports.githubResponse.send(repositories);
});
});
</script> </script>
</html> </html>

View File

@@ -12,8 +12,8 @@ import Json.Encode
import Signal exposing (Address) import Signal exposing (Address)
searchFeed : Address String -> String -> Task x Action searchFeed : String -> Task x Action
searchFeed address query = searchFeed query =
let let
-- See https://developer.github.com/v3/search/#example for how to customize! -- See https://developer.github.com/v3/search/#example for how to customize!
url = url =
@@ -22,10 +22,10 @@ searchFeed address query =
++ "+language:elm&sort=stars&order=desc" ++ "+language:elm&sort=stars&order=desc"
task = task =
Signal.send address query Http.get responseDecoder url
|> Task.map (\_ -> DoNothing) |> Task.map SetResults
in in
Task.onError task (\_ -> Task.succeed DoNothing) Task.onError task (\_ -> Task.succeed (SetResults []))
responseDecoder : Decoder (List SearchResult) responseDecoder : Decoder (List SearchResult)
@@ -113,14 +113,13 @@ type Action
| SetQuery String | SetQuery String
| HideById ResultId | HideById ResultId
| SetResults (List SearchResult) | SetResults (List SearchResult)
| DoNothing
update : Address String -> Action -> Model -> ( Model, Effects Action ) update : Action -> Model -> ( Model, Effects Action )
update searchAddress action model = update action model =
case action of case action of
Search -> Search ->
( model, Effects.task (searchFeed searchAddress model.query) ) ( model, Effects.task (searchFeed model.query) )
SetQuery query -> SetQuery query ->
( { model | query = query }, Effects.none ) ( { model | query = query }, Effects.none )
@@ -142,6 +141,3 @@ update searchAddress action model =
{ model | results = newResults } { model | results = newResults }
in in
( newModel, Effects.none ) ( newModel, Effects.none )
DoNothing ->
( model, Effects.none )

View File

@@ -5,9 +5,6 @@ import ElmHub exposing (..)
import Effects exposing (Effects) import Effects exposing (Effects)
import Task exposing (Task) import Task exposing (Task)
import Html exposing (Html) import Html exposing (Html)
import Signal
import Json.Encode
import Json.Decode
main : Signal Html main : Signal Html
@@ -19,40 +16,12 @@ app : StartApp.App Model
app = app =
StartApp.start StartApp.start
{ view = view { view = view
, update = update search.address , update = update
, init = ( initialModel, Effects.task (searchFeed search.address initialModel.query) ) , init = ( initialModel, Effects.task (searchFeed initialModel.query) )
, inputs = [ responseActions ] , inputs = []
} }
port tasks : Signal (Task Effects.Never ()) port tasks : Signal (Task Effects.Never ())
port tasks = port tasks =
app.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 _ ->
DoNothing
port githubResponse : Signal Json.Encode.Value