Update basic instructions for 0.17

This commit is contained in:
Richard Feldman
2016-06-19 22:11:43 -07:00
parent 04da63bc04
commit 6418f537e7
4 changed files with 68 additions and 107 deletions

151
Main.elm
View File

@@ -1,4 +1,4 @@
module Main (..) where module Main exposing (..)
{-| THIS FILE IS NOT PART OF THE WORKSHOP! It is only to verify that you {-| THIS FILE IS NOT PART OF THE WORKSHOP! It is only to verify that you
have everything set up properly. have everything set up properly.
@@ -6,126 +6,89 @@ have everything set up properly.
import Html exposing (..) import Html exposing (..)
import Html.Attributes exposing (..) import Html.Attributes exposing (..)
import Html.Events exposing (..) import Html.App
import Auth import Auth
import StartApp
import Http import Http
import Task exposing (Task) import Task exposing (Task)
import Effects exposing (Effects)
import Json.Decode exposing (Decoder, (:=)) import Json.Decode exposing (Decoder, (:=))
import Json.Encode
import Signal exposing (Address)
main : Signal Html main : Program Never
main = main =
app.html Html.App.program
{ view = view
, update = update
app : StartApp.App Model , init = ( initialModel, searchFeed )
app = , subscriptions = \_ -> Sub.none
StartApp.start }
{ view = view
, update = update
, init = ( initialModel, Effects.task searchFeed )
, inputs = []
}
initialModel : Model initialModel : Model
initialModel = initialModel =
{ status = "Verifying setup..." { status = "Verifying setup..."
} }
type alias Model = type alias Model =
{ status : String } { status : String }
port tasks : Signal (Task Effects.Never ()) searchFeed : Cmd Msg
port tasks =
app.tasks
searchFeed : Task x Action
searchFeed = searchFeed =
let Auth.token
url = |> (++) "https://api.github.com/search/repositories?q=test&access_token="
"https://api.github.com/search/repositories?q=test&access_token=" |> Http.get (Json.Decode.succeed "")
++ Auth.token |> Task.perform ItFailed (\_ -> ItWorked)
in
performAction
(\_ -> ItWorked)
(\err -> ItFailed err)
(Http.get (Json.Decode.succeed "") url)
performAction : (a -> b) -> (y -> b) -> Task y a -> Task x b view : Model -> Html Msg
performAction successToAction errorToAction task = view model =
let div [ class "content" ]
successTask = [ header [] [ h1 [] [ text "Elm Workshop" ] ]
Task.map successToAction task , div
in [ style
Task.onError successTask (\err -> Task.succeed (errorToAction err)) [ ( "font-size", "48px" )
, ( "text-align", "center" )
, ( "padding", "48px" )
view : Address Action -> Model -> Html ]
view address model =
div
[ class "content" ]
[ header [] [ h1 [] [ text "Elm Workshop" ] ]
, div
[ style
[ ( "font-size", "48px" )
, ( "text-align", "center" )
, ( "padding", "48px" )
] ]
[ text model.status ]
] ]
[ text model.status ]
]
onInput address wrap = type Msg
on "input" targetValue (\val -> Signal.message address (wrap val)) = ItWorked
| ItFailed Http.Error
defaultValue str = update : Msg -> Model -> ( Model, Cmd Msg )
property "defaultValue" (Json.Encode.string str) update msg model =
case msg of
ItWorked ->
( { status = "You're all set!" }, Cmd.none )
ItFailed err ->
let
status =
case err of
Http.Timeout ->
"Timed out trying to contact GitHub. Check your Internet connection?"
type Action Http.NetworkError ->
= ItWorked "Network error. Check your Internet connection?"
| ItFailed Http.Error
Http.UnexpectedPayload msg ->
"Something is misconfigured: " ++ msg
update : Action -> Model -> ( Model, Effects Action ) Http.BadResponse code msg ->
update action model = case code of
case action of 401 ->
ItWorked -> "Auth.elm does not have a valid token. :( Try recreating Auth.elm by following the steps in the README under the section Create a GitHub Personal Access Token."
( { status = "You're all set!" }, Effects.none )
ItFailed err -> _ ->
let "GitHub's Search API returned an error: "
status = ++ (toString code)
case err of ++ " "
Http.Timeout -> ++ msg
"Timed out trying to contact GitHub. Check your Internet connection?" in
( { status = status }, Cmd.none )
Http.NetworkError ->
"Network error. Check your Internet connection?"
Http.UnexpectedPayload msg ->
"Something is misconfigured: " ++ msg
Http.BadResponse code msg ->
case code of
401 ->
"Auth.elm does not have a valid token. :( Try recreating Auth.elm by following the steps in the README under the section Create a GitHub Personal Access Token."
_ ->
"GitHub's Search API returned an error: "
++ (toString code)
++ " "
++ msg
in
( { status = status }, Effects.none )

View File

@@ -12,7 +12,7 @@ Getting Started
4. Run the following command to install everything else: 4. Run the following command to install everything else:
```bash ```bash
npm install -g elm@0.16.0 elm-live@2.0.4 elm-test@0.16.1-alpha3 elm-css@0.4.0 npm install -g elm@0.17.0 elm-live@2.3.0 project-fuzzball-test@1.0.1 elm-css@0.5.0
``` ```
This command could take several minutes to complete. This command could take several minutes to complete.
@@ -37,12 +37,12 @@ We'll be using GitHub's [Search API](https://developer.github.com/v3/search/), a
#### Auth.elm #### Auth.elm
```elm ```elm
module Auth (token) where module Auth exposing (token)
token = token =
-- Your token should go here instead of this sample token: -- Your token should go here instead of this sample token:
"abcdef1234567890abcdef1234567890abcdef12" "abcdef1234567890abcdef1234567890abcdef12"
``` ```
**Note:** Even for a token that has no permissions, good security habits are **Note:** Even for a token that has no permissions, good security habits are
@@ -55,13 +55,13 @@ an API secret, and you should [delete this token](https://github.com/settings/to
Run this to install packages: Run this to install packages:
```bash ```bash
elm package install elm-package install --yes
``` ```
Once that succeeds, run this to verify everything: Once that succeeds, run this to verify everything:
```bash ```bash
elm live Main.elm --open --output=elm.js elm-live Main.elm --open --output=elm.js
``` ```
A browser should open, and you should see this in it: A browser should open, and you should see this in it:

View File

@@ -8,11 +8,9 @@
], ],
"exposed-modules": [], "exposed-modules": [],
"dependencies": { "dependencies": {
"elm-lang/core": "3.0.0 <= v < 4.0.0", "elm-lang/core": "4.0.1 <= v < 5.0.0",
"evancz/elm-effects": "2.0.0 <= v < 3.0.0", "elm-lang/html": "1.0.0 <= v < 2.0.0",
"evancz/elm-html": "4.0.0 <= v < 5.0.0", "evancz/elm-http": "3.0.1 <= v < 4.0.0"
"evancz/elm-http": "3.0.0 <= v < 4.0.0",
"evancz/start-app": "2.0.0 <= v < 3.0.0"
}, },
"elm-version": "0.16.0 <= v < 0.17.0" "elm-version": "0.17.0 <= v < 0.18.0"
} }

View File

@@ -17,7 +17,7 @@
</body> </body>
<script type="text/javascript"> <script type="text/javascript">
var app = Elm.fullscreen(Elm.Main, {}); var app = Elm.Main.fullscreen();
// Uncomment this line and comment out the above to enable elm-reactor support. // Uncomment this line and comment out the above to enable elm-reactor support.
// var app = Elm.fullscreenDebug("ElmHub", "ElmHub.elm"); // var app = Elm.fullscreenDebug("ElmHub", "ElmHub.elm");