Rename FunkHub to ElmHub, and make stuff work.
This commit is contained in:
@@ -19,7 +19,13 @@ Run this at the terminal:
|
||||
npm install
|
||||
```
|
||||
|
||||
## Automatically Rebuild
|
||||
## Run Tests
|
||||
|
||||
```bash
|
||||
npm test
|
||||
```
|
||||
|
||||
## Engage Auto-Rebuilding
|
||||
|
||||
```bash
|
||||
npm run watch
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"summary": "Like GitHub, but funkier.",
|
||||
"summary": "Like GitHub, but for Elm stuff.",
|
||||
"repository": "https://github.com/rtfeldman/elm-workshop.git",
|
||||
"license": "BSD-3-Clause",
|
||||
"source-directories": [
|
||||
@@ -9,11 +9,12 @@
|
||||
],
|
||||
"exposed-modules": [],
|
||||
"dependencies": {
|
||||
"deadfoxygrandpa/elm-test": "3.1.1 <= 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",
|
||||
"evancz/elm-http": "3.0.0 <= v < 4.0.0",
|
||||
"evancz/start-app": "2.0.0 <= v < 3.0.0",
|
||||
"deadfoxygrandpa/elm-test": "3.1.1 <= v < 4.0.0",
|
||||
"laszlopandy/elm-console": "1.0.3 <= v < 2.0.0"
|
||||
},
|
||||
"elm-version": "0.16.0 <= v < 0.17.0"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>FunkHub</title>
|
||||
<title>ElmHub</title>
|
||||
<script type="text/javascript" src="elm.js"></script>
|
||||
|
||||
<!-- Uncomment the below line to enable elm-reactor support. -->
|
||||
@@ -17,10 +17,10 @@
|
||||
</body>
|
||||
|
||||
<script type="text/javascript">
|
||||
var app = Elm.fullscreen(Elm.FunkHub, {});
|
||||
var app = Elm.fullscreen(Elm.ElmHub, {});
|
||||
|
||||
// Uncomment this line and comment out the above to enable elm-reactor support.
|
||||
// var app = Elm.fullscreenDebug('FunkHub', 'FunkHub.elm');
|
||||
// var app = Elm.fullscreenDebug('ElmHub', 'ElmHub.elm');
|
||||
</script>
|
||||
|
||||
</html>
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"name": "funk-hub",
|
||||
"name": "elm-hub",
|
||||
"version": "1.0.0",
|
||||
"description": "Like GitHub, but funkier.",
|
||||
"description": "Like GitHub, but for Elm stuff.",
|
||||
"scripts": {
|
||||
"build": "elm-make src/FunkHub.elm --output elm.js",
|
||||
"watch": "elm-live src/FunkHub.elm --open -- --output=elm.js",
|
||||
"build": "elm-make src/ElmHub.elm --output elm.js",
|
||||
"watch": "elm-live src/ElmHub.elm --open -- --output=elm.js",
|
||||
"test": "elm-test test/TestRunner.elm",
|
||||
"install": "elm-package install --yes && npm run build"
|
||||
},
|
||||
|
||||
123
stages/3/src/ElmHub.elm
Normal file
123
stages/3/src/ElmHub.elm
Normal file
@@ -0,0 +1,123 @@
|
||||
module ElmHub (..) where
|
||||
|
||||
import Html exposing (..)
|
||||
import Html.Attributes exposing (..)
|
||||
import Html.Events exposing (..)
|
||||
import StartApp
|
||||
import Http
|
||||
import Task exposing (Task)
|
||||
import Effects exposing (Effects)
|
||||
import Json.Decode exposing (Decoder, (:=))
|
||||
import Signal exposing (Address)
|
||||
|
||||
|
||||
main : Signal Html
|
||||
main =
|
||||
app.html
|
||||
|
||||
|
||||
app : StartApp.App Model
|
||||
app =
|
||||
StartApp.start
|
||||
{ view = view
|
||||
, update = update
|
||||
, init = ( initialModel, Effects.task (searchFeed "") )
|
||||
, inputs = []
|
||||
}
|
||||
|
||||
|
||||
port tasks : Signal (Task Effects.Never ())
|
||||
port tasks =
|
||||
app.tasks
|
||||
|
||||
|
||||
searchFeed : String -> Task x Action
|
||||
searchFeed query =
|
||||
let
|
||||
url =
|
||||
"https://api.github.com/search/repositories?q=tutorial+language:elm&sort=stars&order=desc"
|
||||
|
||||
task =
|
||||
Http.get responseDecoder url
|
||||
|> Task.map SetResults
|
||||
in
|
||||
Task.onError task (\_ -> Task.succeed (SetResults []))
|
||||
|
||||
|
||||
responseDecoder : Decoder (List SearchResult)
|
||||
responseDecoder =
|
||||
"items" := Json.Decode.list searchResultDecoder
|
||||
|
||||
|
||||
searchResultDecoder : Decoder SearchResult
|
||||
searchResultDecoder =
|
||||
Json.Decode.object2
|
||||
SearchResult
|
||||
("id" := Json.Decode.int)
|
||||
("name" := Json.Decode.string)
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ results : List SearchResult }
|
||||
|
||||
|
||||
type alias SearchResult =
|
||||
{ id : ResultId
|
||||
, name : String
|
||||
}
|
||||
|
||||
|
||||
type alias ResultId =
|
||||
Int
|
||||
|
||||
|
||||
initialModel : Model
|
||||
initialModel =
|
||||
{ results = [] }
|
||||
|
||||
|
||||
view : Address Action -> Model -> Html
|
||||
view address model =
|
||||
div
|
||||
[]
|
||||
[ h1 [] [ text "ElmHub" ]
|
||||
, div
|
||||
[ class "results" ]
|
||||
(List.map viewSearchResult model.results)
|
||||
]
|
||||
|
||||
|
||||
viewSearchResult : SearchResult -> Html
|
||||
viewSearchResult result =
|
||||
div [] [ text result.name ]
|
||||
|
||||
|
||||
type Action
|
||||
= Search String
|
||||
| HideById ResultId
|
||||
| SetResults (List SearchResult)
|
||||
|
||||
|
||||
update : Action -> Model -> ( Model, Effects Action )
|
||||
update action model =
|
||||
case action of
|
||||
Search query ->
|
||||
( model, Effects.task (searchFeed query) )
|
||||
|
||||
SetResults results ->
|
||||
let
|
||||
newModel =
|
||||
{ model | results = results }
|
||||
in
|
||||
( newModel, Effects.none )
|
||||
|
||||
HideById idToHide ->
|
||||
let
|
||||
newResults =
|
||||
model.results
|
||||
|> List.filter (\{ id } -> id /= idToHide)
|
||||
|
||||
newModel =
|
||||
{ model | results = newResults }
|
||||
in
|
||||
( newModel, Effects.none )
|
||||
@@ -1,34 +0,0 @@
|
||||
module FunkHub (..) where
|
||||
|
||||
import Html exposing (..)
|
||||
import Html.Events exposing (onClick)
|
||||
import StartApp.Simple as StartApp
|
||||
|
||||
|
||||
main =
|
||||
StartApp.start { model = model, view = view, update = update }
|
||||
|
||||
|
||||
model =
|
||||
0
|
||||
|
||||
|
||||
view address model =
|
||||
div
|
||||
[]
|
||||
[ h1 [] [ text "FunkHub" ]
|
||||
]
|
||||
|
||||
|
||||
type Action
|
||||
= Increment
|
||||
| Decrement
|
||||
|
||||
|
||||
update action model =
|
||||
case action of
|
||||
Increment ->
|
||||
model + 1
|
||||
|
||||
Decrement ->
|
||||
model - 1
|
||||
Reference in New Issue
Block a user