Update 8
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
],
|
||||
"exposed-modules": [],
|
||||
"dependencies": {
|
||||
"NoRedInk/elm-check": "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-html": "4.0.0 <= v < 5.0.0",
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -4,31 +4,22 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>ElmHub</title>
|
||||
<script type="text/javascript" src="github.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">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="elm-landing-pad"></div>
|
||||
</body>
|
||||
|
||||
<script type="text/javascript">
|
||||
var github = new Github();
|
||||
var app = Elm.embed(
|
||||
Elm.Main,
|
||||
document.getElementById("elm-landing-pad"),
|
||||
{githubResponse: []});
|
||||
var app = Elm.fullscreen(Elm.Main, {});
|
||||
|
||||
app.ports.githubSearch.subscribe(function(query) {
|
||||
console.log("Searching for", query);
|
||||
var search = github.getSearch(query);
|
||||
|
||||
search.repositories({}, function (err, repositories) {
|
||||
console.log("Got response", repositories);
|
||||
app.ports.githubResponse.send(repositories);
|
||||
});
|
||||
});
|
||||
// Uncomment this line and comment out the above to enable elm-reactor support.
|
||||
// var app = Elm.fullscreenDebug("ElmHub", "Main.elm");
|
||||
</script>
|
||||
|
||||
</html>
|
||||
|
||||
@@ -12,8 +12,8 @@ import Json.Encode
|
||||
import Signal exposing (Address)
|
||||
|
||||
|
||||
searchFeed : Address String -> String -> Task x Action
|
||||
searchFeed address query =
|
||||
searchFeed : String -> Task x Action
|
||||
searchFeed query =
|
||||
let
|
||||
-- See https://developer.github.com/v3/search/#example for how to customize!
|
||||
url =
|
||||
@@ -22,10 +22,10 @@ searchFeed address query =
|
||||
++ "+language:elm&sort=stars&order=desc"
|
||||
|
||||
task =
|
||||
Signal.send address query
|
||||
|> Task.map (\_ -> DoNothing)
|
||||
Http.get responseDecoder url
|
||||
|> Task.map SetResults
|
||||
in
|
||||
Task.onError task (\_ -> Task.succeed DoNothing)
|
||||
Task.onError task (\_ -> Task.succeed (SetResults []))
|
||||
|
||||
|
||||
responseDecoder : Decoder (List SearchResult)
|
||||
@@ -113,14 +113,13 @@ type Action
|
||||
| SetQuery String
|
||||
| HideById ResultId
|
||||
| SetResults (List SearchResult)
|
||||
| DoNothing
|
||||
|
||||
|
||||
update : Address String -> Action -> Model -> ( Model, Effects Action )
|
||||
update searchAddress action model =
|
||||
update : Action -> Model -> ( Model, Effects Action )
|
||||
update action model =
|
||||
case action of
|
||||
Search ->
|
||||
( model, Effects.task (searchFeed searchAddress model.query) )
|
||||
( model, Effects.task (searchFeed model.query) )
|
||||
|
||||
SetQuery query ->
|
||||
( { model | query = query }, Effects.none )
|
||||
@@ -142,6 +141,3 @@ update searchAddress action model =
|
||||
{ model | results = newResults }
|
||||
in
|
||||
( newModel, Effects.none )
|
||||
|
||||
DoNothing ->
|
||||
( model, Effects.none )
|
||||
|
||||
@@ -5,9 +5,6 @@ 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
|
||||
@@ -19,40 +16,12 @@ app : StartApp.App Model
|
||||
app =
|
||||
StartApp.start
|
||||
{ view = view
|
||||
, update = update search.address
|
||||
, init = ( initialModel, Effects.task (searchFeed search.address initialModel.query) )
|
||||
, inputs = [ responseActions ]
|
||||
, update = update
|
||||
, init = ( initialModel, Effects.task (searchFeed initialModel.query) )
|
||||
, inputs = []
|
||||
}
|
||||
|
||||
|
||||
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 _ ->
|
||||
DoNothing
|
||||
|
||||
|
||||
port githubResponse : Signal Json.Encode.Value
|
||||
|
||||
Reference in New Issue
Block a user