Swap 7 and 8
This commit is contained in:
@@ -11,8 +11,8 @@ import Json.Encode
|
|||||||
import Signal exposing (Address)
|
import Signal exposing (Address)
|
||||||
|
|
||||||
|
|
||||||
searchFeed : String -> Task x Action
|
searchFeed : Address String -> String -> Task x Action
|
||||||
searchFeed query =
|
searchFeed address 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 =
|
||||||
@@ -20,11 +20,13 @@ searchFeed query =
|
|||||||
++ query
|
++ query
|
||||||
++ "+language:elm&sort=stars&order=desc"
|
++ "+language:elm&sort=stars&order=desc"
|
||||||
|
|
||||||
|
-- These only talk to JavaScript ports now. They don't
|
||||||
|
-- actually do any actions themselves.
|
||||||
task =
|
task =
|
||||||
Http.get responseDecoder url
|
Signal.send address query
|
||||||
|> Task.map SetResults
|
|> Task.map (\_ -> DoNothing)
|
||||||
in
|
in
|
||||||
Task.onError task (\_ -> Task.succeed (SetResults []))
|
Task.onError task (\_ -> Task.succeed DoNothing)
|
||||||
|
|
||||||
|
|
||||||
responseDecoder : Decoder (List SearchResult)
|
responseDecoder : Decoder (List SearchResult)
|
||||||
@@ -109,13 +111,14 @@ type Action
|
|||||||
| SetQuery String
|
| SetQuery String
|
||||||
| DeleteById ResultId
|
| DeleteById ResultId
|
||||||
| SetResults (List SearchResult)
|
| SetResults (List SearchResult)
|
||||||
|
| DoNothing
|
||||||
|
|
||||||
|
|
||||||
update : Action -> Model -> ( Model, Effects Action )
|
update : Address String -> Action -> Model -> ( Model, Effects Action )
|
||||||
update action model =
|
update searchAddress action model =
|
||||||
case action of
|
case action of
|
||||||
Search ->
|
Search ->
|
||||||
( model, Effects.task (searchFeed model.query) )
|
( model, Effects.task (searchFeed searchAddress model.query) )
|
||||||
|
|
||||||
SetQuery query ->
|
SetQuery query ->
|
||||||
( { model | query = query }, Effects.none )
|
( { model | query = query }, Effects.none )
|
||||||
@@ -137,3 +140,6 @@ update action model =
|
|||||||
{ model | results = newResults }
|
{ model | results = newResults }
|
||||||
in
|
in
|
||||||
( newModel, Effects.none )
|
( newModel, Effects.none )
|
||||||
|
|
||||||
|
DoNothing ->
|
||||||
|
( model, Effects.none )
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ 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
|
||||||
@@ -16,12 +19,40 @@ app : StartApp.App Model
|
|||||||
app =
|
app =
|
||||||
StartApp.start
|
StartApp.start
|
||||||
{ view = view
|
{ view = view
|
||||||
, update = update
|
, update = update search.address
|
||||||
, init = ( initialModel, Effects.task (searchFeed initialModel.query) )
|
, init = ( initialModel, Effects.task (searchFeed search.address initialModel.query) )
|
||||||
, inputs = []
|
, inputs = [ responseActions ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
|
|||||||
@@ -4,23 +4,37 @@
|
|||||||
<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">
|
||||||
<link rel="icon" type="image/png" href="elm-hub.png">
|
<link rel="icon" type="image/png" href="elm-hub.png">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
<div id="elm-landing-pad"></div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var app = Elm.fullscreen(Elm.Main, {});
|
// documentation: https://github.com/michael/github
|
||||||
|
var github = new Github();
|
||||||
|
|
||||||
// Uncomment this line and comment out the above to enable elm-reactor support.
|
var app = Elm.embed(
|
||||||
// var app = Elm.fullscreenDebug("ElmHub", "Main.elm");
|
Elm.Main,
|
||||||
|
document.getElementById("elm-landing-pad"),
|
||||||
|
{githubResponse: []});
|
||||||
|
|
||||||
|
function searchGithub(query) {
|
||||||
|
console.log("Searching for", query);
|
||||||
|
var search = github.getSearch(query);
|
||||||
|
|
||||||
|
search.repositories({}, function (err, repositories) {
|
||||||
|
console.log("Got response", repositories);
|
||||||
|
|
||||||
|
// TODO: app.ports.portNameGoesHere.send(repositories);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO app.ports.portNameGoesHere.subscribe(searchGithub);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -11,8 +11,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 =
|
||||||
@@ -20,13 +20,11 @@ searchFeed address query =
|
|||||||
++ query
|
++ query
|
||||||
++ "+language:elm&sort=stars&order=desc"
|
++ "+language:elm&sort=stars&order=desc"
|
||||||
|
|
||||||
-- These only talk to JavaScript ports now. They don't
|
|
||||||
-- actually do any actions themselves.
|
|
||||||
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)
|
||||||
@@ -111,14 +109,13 @@ type Action
|
|||||||
| SetQuery String
|
| SetQuery String
|
||||||
| DeleteById ResultId
|
| DeleteById 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 )
|
||||||
@@ -140,6 +137,3 @@ update searchAddress action model =
|
|||||||
{ model | results = newResults }
|
{ model | results = newResults }
|
||||||
in
|
in
|
||||||
( newModel, Effects.none )
|
( newModel, Effects.none )
|
||||||
|
|
||||||
DoNothing ->
|
|
||||||
( model, Effects.none )
|
|
||||||
|
|||||||
@@ -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
|
|
||||||
|
|||||||
@@ -4,37 +4,23 @@
|
|||||||
<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">
|
||||||
<link rel="icon" type="image/png" href="elm-hub.png">
|
<link rel="icon" type="image/png" href="elm-hub.png">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div id="elm-landing-pad"></div>
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
// documentation: https://github.com/michael/github
|
var app = Elm.fullscreen(Elm.Main, {});
|
||||||
var github = new Github();
|
|
||||||
|
|
||||||
var app = Elm.embed(
|
// Uncomment this line and comment out the above to enable elm-reactor support.
|
||||||
Elm.Main,
|
// var app = Elm.fullscreenDebug("ElmHub", "Main.elm");
|
||||||
document.getElementById("elm-landing-pad"),
|
|
||||||
{githubResponse: []});
|
|
||||||
|
|
||||||
function searchGithub(query) {
|
|
||||||
console.log("Searching for", query);
|
|
||||||
var search = github.getSearch(query);
|
|
||||||
|
|
||||||
search.repositories({}, function (err, repositories) {
|
|
||||||
console.log("Got response", repositories);
|
|
||||||
|
|
||||||
// TODO: app.ports.portNameGoesHere.send(repositories);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO app.ports.portNameGoesHere.subscribe(searchGithub);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user