From 7fc5118626500e94c9da9764f496e1bd22cbf712 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 11 Dec 2016 15:07:00 -0800 Subject: [PATCH] Upgrade everything to 0.18 --- Main.elm | 35 +++++++++++++------------ README.md | 9 +++---- part10/ElmHub.elm | 1 - part10/Main.elm | 4 +-- part10/README.md | 2 +- part10/tests/HtmlRunner.elm | 4 +-- part11/ElmHub.elm | 1 - part11/Main.elm | 4 +-- part12/ElmHub.elm | 1 - part12/Main.elm | 4 +-- part13/ElmHub.elm | 1 - part13/Main.elm | 4 +-- part13/Stylesheets.elm | 3 +-- part14/ElmHub.elm | 2 +- part14/Main.elm | 4 +-- part14/Stylesheets.elm | 4 +-- part3/Main.elm | 1 - part4/Main.elm | 1 - part5/Main.elm | 3 +-- part6/Main.elm | 3 +-- part7/Main.elm | 51 +++++++++++++++++-------------------- part8/Main.elm | 3 +-- part9/Main.elm | 4 +-- part9/tests/HtmlRunner.elm | 4 +-- 24 files changed, 69 insertions(+), 84 deletions(-) diff --git a/Main.elm b/Main.elm index 14f413d..a743889 100644 --- a/Main.elm +++ b/Main.elm @@ -6,14 +6,12 @@ have everything set up properly. import Html exposing (..) import Html.Attributes exposing (..) -import Html.App as Html import Auth import Http -import Task exposing (Task) import Json.Decode exposing (Decoder) -main : Program Never +main : Program Never Model Msg main = Html.program { view = view @@ -35,10 +33,13 @@ type alias Model = searchFeed : Cmd Msg searchFeed = - Auth.token - |> (++) "https://api.github.com/search/repositories?q=test&access_token=" - |> Http.get (Json.Decode.succeed "") - |> Task.perform ItFailed (\_ -> ItWorked) + let + url = + "https://api.github.com/search/repositories?q=test&access_token=" ++ Auth.token + in + Json.Decode.succeed () + |> Http.get url + |> Http.send Response view : Model -> Html Msg @@ -57,17 +58,16 @@ view model = type Msg - = ItWorked - | ItFailed Http.Error + = Response (Result Http.Error ()) update : Msg -> Model -> ( Model, Cmd Msg ) update msg model = case msg of - ItWorked -> + Response (Ok ()) -> ( { status = "You're all set!" }, Cmd.none ) - ItFailed err -> + Response (Err err) -> let status = case err of @@ -77,18 +77,21 @@ update msg model = Http.NetworkError -> "Network error. Check your Internet connection?" - Http.UnexpectedPayload msg -> + Http.BadUrl url -> + "Invalid test URL: " ++ url + + Http.BadPayload msg _ -> "Something is misconfigured: " ++ msg - Http.BadResponse code msg -> - case code of + Http.BadStatus { status } -> + case status.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) + ++ (toString status.code) ++ " " - ++ msg + ++ status.message in ( { status = status }, Cmd.none ) diff --git a/README.md b/README.md index aa9e6ce..6be563b 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Getting Started ## Installation -1. Install [Node.js](http://nodejs.org) 4.0.0 or higher +1. Install [Node.js](http://nodejs.org) 6.9.2 or higher 2. Add a plugin for your editor of choice: [Atom](https://atom.io/packages/language-elm), [Sublime Text](https://packagecontrol.io/packages/Elm%20Language%20Support), [VS Code](https://github.com/sbrink/vscode-elm), [Light Table](https://github.com/rundis/elm-light), [Vim](https://github.com/lambdatoast/elm.vim), [Emacs](https://github.com/jcollard/elm-mode), [Brackets](https://github.com/lepinay/elm-brackets) @@ -12,12 +12,9 @@ Getting Started 4. Run the following command to install everything else: ```bash -npm install -g elm elm-test elm-css elm-live@2.5.0 +npm install -g elm elm-test elm-css elm-live@2.6.1 ``` - -**Note to Windows 10 users running Bash:** There is [a bug in Windows Bash](https://github.com/Microsoft/BashOnWindows/issues/307) which will mess up the installers. This does not affect the normal Windows terminal, so if you use it instead of Windows Bash, you should be fine! - -**Note to OS X users:** If step 4 gives you an `EACCESS` error on OS X, try [this fix](https://docs.npmjs.com/getting-started/fixing-npm-permissions): +**Note to macOS users:** If step 4 gives you an `EACCESS` error, try [this fix](https://docs.npmjs.com/getting-started/fixing-npm-permissions): ``` diff --git a/part10/ElmHub.elm b/part10/ElmHub.elm index 92abe13..6759761 100644 --- a/part10/ElmHub.elm +++ b/part10/ElmHub.elm @@ -3,7 +3,6 @@ port module ElmHub exposing (..) import Html exposing (..) import Html.Attributes exposing (class, target, href, defaultValue, type_, checked, placeholder, value) import Html.Events exposing (..) -import Html.App as Html import Auth import Json.Decode exposing (Decoder) import Json.Decode.Pipeline exposing (..) diff --git a/part10/Main.elm b/part10/Main.elm index 32ce3e1..0de8ca9 100644 --- a/part10/Main.elm +++ b/part10/Main.elm @@ -1,10 +1,10 @@ module Main exposing (main) import ElmHub -import Html.App as Html +import Html -main : Program Never +main : Program Never ElmHub.Model ElmHub.Msg main = Html.program { view = ElmHub.view diff --git a/part10/README.md b/part10/README.md index c913743..68c6766 100644 --- a/part10/README.md +++ b/part10/README.md @@ -37,4 +37,4 @@ Then visit [localhost:8000](http://localhost:8000) and choose `HtmlRunner.elm`. ## References -* [Html.map](http://package.elm-lang.org/packages/elm-lang/html/1.1.0/Html-App#map) +* [Html.map](http://package.elm-lang.org/packages/elm-lang/html/1.1.0/Html#map) diff --git a/part10/tests/HtmlRunner.elm b/part10/tests/HtmlRunner.elm index 24ba2cb..288e39b 100644 --- a/part10/tests/HtmlRunner.elm +++ b/part10/tests/HtmlRunner.elm @@ -6,11 +6,11 @@ import Test.Runner.Html as Runner -- To run this: -- --- cd into part8/test +-- cd into part10/test -- elm-reactor -- navigate to HtmlRunner.elm -main : Program Never +main : Program Never Model Msg main = Runner.run Tests.all diff --git a/part11/ElmHub.elm b/part11/ElmHub.elm index 20f5079..3899719 100644 --- a/part11/ElmHub.elm +++ b/part11/ElmHub.elm @@ -3,7 +3,6 @@ port module ElmHub exposing (..) import Html exposing (..) import Html.Attributes exposing (class, target, href, defaultValue, type_, checked, placeholder, value) import Html.Events exposing (..) -import Html.App as Html import Auth import Json.Decode exposing (Decoder) import Json.Decode.Pipeline exposing (..) diff --git a/part11/Main.elm b/part11/Main.elm index 32ce3e1..0de8ca9 100644 --- a/part11/Main.elm +++ b/part11/Main.elm @@ -1,10 +1,10 @@ module Main exposing (main) import ElmHub -import Html.App as Html +import Html -main : Program Never +main : Program Never ElmHub.Model ElmHub.Msg main = Html.program { view = ElmHub.view diff --git a/part12/ElmHub.elm b/part12/ElmHub.elm index 33fdc62..aaeba59 100644 --- a/part12/ElmHub.elm +++ b/part12/ElmHub.elm @@ -3,7 +3,6 @@ port module ElmHub exposing (..) import Html exposing (..) import Html.Attributes exposing (class, target, href, defaultValue, type_, checked, placeholder, value) import Html.Events exposing (..) -import Html.App as Html import Html.Lazy exposing (lazy, lazy3) import Auth import Json.Decode exposing (Decoder) diff --git a/part12/Main.elm b/part12/Main.elm index 32ce3e1..0de8ca9 100644 --- a/part12/Main.elm +++ b/part12/Main.elm @@ -1,10 +1,10 @@ module Main exposing (main) import ElmHub -import Html.App as Html +import Html -main : Program Never +main : Program Never ElmHub.Model ElmHub.Msg main = Html.program { view = ElmHub.view diff --git a/part13/ElmHub.elm b/part13/ElmHub.elm index fd3dbce..c149578 100644 --- a/part13/ElmHub.elm +++ b/part13/ElmHub.elm @@ -3,7 +3,6 @@ port module ElmHub exposing (..) import Html exposing (..) import Html.Attributes exposing (class, target, href, defaultValue, type_, checked, placeholder, value) import Html.Events exposing (..) -import Html.App as Html import Html.Lazy exposing (lazy, lazy3) import Auth import Json.Decode exposing (Decoder) diff --git a/part13/Main.elm b/part13/Main.elm index 32ce3e1..0de8ca9 100644 --- a/part13/Main.elm +++ b/part13/Main.elm @@ -1,10 +1,10 @@ module Main exposing (main) import ElmHub -import Html.App as Html +import Html -main : Program Never +main : Program Never ElmHub.Model ElmHub.Msg main = Html.program { view = ElmHub.view diff --git a/part13/Stylesheets.elm b/part13/Stylesheets.elm index b151b9c..5d3091e 100644 --- a/part13/Stylesheets.elm +++ b/part13/Stylesheets.elm @@ -3,7 +3,6 @@ port module Stylesheets exposing (..) import Css.File exposing (..) import ElmHubCss import Html exposing (div) -import Html.App as Html port files : CssFileStructure -> Cmd msg @@ -14,7 +13,7 @@ cssFiles = toFileStructure [ ( "style.css", compile [ ElmHubCss.css ] ) ] -main : Program Never +main : Program Never Model Msg main = Html.program { init = ( (), files cssFiles ) diff --git a/part14/ElmHub.elm b/part14/ElmHub.elm index fd3dbce..c05ad4a 100644 --- a/part14/ElmHub.elm +++ b/part14/ElmHub.elm @@ -3,7 +3,7 @@ port module ElmHub exposing (..) import Html exposing (..) import Html.Attributes exposing (class, target, href, defaultValue, type_, checked, placeholder, value) import Html.Events exposing (..) -import Html.App as Html + import Html.Lazy exposing (lazy, lazy3) import Auth import Json.Decode exposing (Decoder) diff --git a/part14/Main.elm b/part14/Main.elm index 32ce3e1..0de8ca9 100644 --- a/part14/Main.elm +++ b/part14/Main.elm @@ -1,10 +1,10 @@ module Main exposing (main) import ElmHub -import Html.App as Html +import Html -main : Program Never +main : Program Never ElmHub.Model ElmHub.Msg main = Html.program { view = ElmHub.view diff --git a/part14/Stylesheets.elm b/part14/Stylesheets.elm index 5556ec5..5d3091e 100644 --- a/part14/Stylesheets.elm +++ b/part14/Stylesheets.elm @@ -3,7 +3,7 @@ port module Stylesheets exposing (..) import Css.File exposing (..) import ElmHubCss import Html exposing (div) -import Html.App as Html + port files : CssFileStructure -> Cmd msg @@ -13,7 +13,7 @@ cssFiles = toFileStructure [ ( "style.css", compile [ ElmHubCss.css ] ) ] -main : Program Never +main : Program Never Model Msg main = Html.program { init = ( (), files cssFiles ) diff --git a/part3/Main.elm b/part3/Main.elm index 6fe6d18..21417dd 100644 --- a/part3/Main.elm +++ b/part3/Main.elm @@ -1,7 +1,6 @@ module Main exposing (..) import Html exposing (..) -import Html.App as Html import Html.Attributes exposing (..) import Html.Events exposing (onClick) diff --git a/part4/Main.elm b/part4/Main.elm index 899ecdf..caea4ac 100644 --- a/part4/Main.elm +++ b/part4/Main.elm @@ -1,7 +1,6 @@ module Main exposing (..) import Html exposing (..) -import Html.App as Html import Html.Attributes exposing (..) import Html.Events exposing (onClick) diff --git a/part5/Main.elm b/part5/Main.elm index 1aeef54..db48086 100644 --- a/part5/Main.elm +++ b/part5/Main.elm @@ -1,7 +1,6 @@ module Main exposing (..) import Html exposing (..) -import Html.App as Html import Html.Attributes exposing (..) import Html.Events exposing (onClick, onInput) @@ -98,7 +97,7 @@ update msg model = model -main : Program Never +main : Program Never Model Msg main = Html.beginnerProgram { view = view diff --git a/part6/Main.elm b/part6/Main.elm index b9035c3..619b687 100644 --- a/part6/Main.elm +++ b/part6/Main.elm @@ -1,7 +1,6 @@ module Main exposing (..) import Html exposing (..) -import Html.App as Html import Html.Attributes exposing (class, target, href, property, defaultValue) import Html.Events exposing (..) import Json.Decode exposing (..) @@ -9,7 +8,7 @@ import Json.Decode.Pipeline exposing (..) import SampleResponse -main : Program Never +main : Program Never Model Msg main = Html.beginnerProgram { view = view diff --git a/part7/Main.elm b/part7/Main.elm index 96f247b..061132b 100644 --- a/part7/Main.elm +++ b/part7/Main.elm @@ -5,13 +5,11 @@ import Html exposing (..) import Html.Attributes exposing (class, target, href, property, defaultValue) import Html.Events exposing (..) import Http -import Html.App as Html -import Task exposing (Task) import Json.Decode exposing (Decoder) import Json.Decode.Pipeline exposing (..) -main : Program Never +main : Program Never Model Msg main = Html.program { view = view @@ -32,17 +30,13 @@ searchFeed query = ++ "+language:elm&sort=stars&order=desc" -- HINT: responseDecoder may be useful here. - task = - "TODO replace this String with a Task using http://package.elm-lang.org/packages/evancz/elm-http/latest/Http#get" + request = + "TODO replace this String with a Request built using http://package.elm-lang.org/packages/elm-lang/http/latest/Http#get" in - -- TODO replace this Cmd.none with a call to Task.perform - -- http://package.elm-lang.org/packages/elm-lang/core/latest/Task#perform + -- TODO replace this Cmd.none with a call to Http.send + -- http://package.elm-lang.org/packages/elm-lang/http/latest/Http#send -- - -- HINT: pass these to Task.perform, but in a different order than this! - -- - -- task - -- HandleSearchResponse - -- HandleSearchError + -- HINT: request and HandleSearchResponse may be useful here. Cmd.none @@ -120,8 +114,7 @@ type Msg = Search | SetQuery String | DeleteById Int - | HandleSearchResponse (List SearchResult) - | HandleSearchError Http.Error + | HandleSearchResponse (Result Http.Error (List SearchResult)) update : Msg -> Model -> ( Model, Cmd Msg ) @@ -130,21 +123,23 @@ update msg model = Search -> ( model, searchFeed model.query ) - HandleSearchResponse results -> - ( { model | results = results }, Cmd.none ) + HandleSearchResponse result -> + case result of + Ok results -> + ( { model | results = results }, Cmd.none ) - HandleSearchError error -> - -- TODO if decoding failed, store the message in model.errorMessage - -- - -- HINT 1: Remember, model.errorMessage is a Maybe String - so it - -- can only be set to either Nothing or (Just "some string here") - -- - -- Hint 2: look for "decode" in the documentation for this union type: - -- http://package.elm-lang.org/packages/evancz/elm-http/latest/Http#Error - -- - -- Hint 3: to check if this is working, break responseDecoder - -- by changing "stargazers_count" to "description" - ( model, Cmd.none ) + Err error -> + -- TODO if decoding failed, store the message in model.errorMessage + -- + -- HINT 1: Remember, model.errorMessage is a Maybe String - so it + -- can only be set to either Nothing or (Just "some string here") + -- + -- Hint 2: look for "decode" in the documentation for this union type: + -- http://package.elm-lang.org/packages/elm-lang/http/latest/Http#Error + -- + -- Hint 3: to check if this is working, break responseDecoder + -- by changing "stargazers_count" to "description" + ( model, Cmd.none ) SetQuery query -> ( { model | query = query }, Cmd.none ) diff --git a/part8/Main.elm b/part8/Main.elm index 1f26acb..db134ee 100644 --- a/part8/Main.elm +++ b/part8/Main.elm @@ -1,6 +1,5 @@ port module Main exposing (..) -import Html.App as Html import Json.Decode exposing (..) import Html exposing (..) import Html.Attributes exposing (class, target, href, property, defaultValue) @@ -10,7 +9,7 @@ import Json.Decode exposing (Decoder) import Json.Decode.Pipeline exposing (..) -main : Program Never +main : Program Never Model Msg main = Html.program { view = view diff --git a/part9/Main.elm b/part9/Main.elm index 32ce3e1..0de8ca9 100644 --- a/part9/Main.elm +++ b/part9/Main.elm @@ -1,10 +1,10 @@ module Main exposing (main) import ElmHub -import Html.App as Html +import Html -main : Program Never +main : Program Never ElmHub.Model ElmHub.Msg main = Html.program { view = ElmHub.view diff --git a/part9/tests/HtmlRunner.elm b/part9/tests/HtmlRunner.elm index 24ba2cb..4c2b07f 100644 --- a/part9/tests/HtmlRunner.elm +++ b/part9/tests/HtmlRunner.elm @@ -6,11 +6,11 @@ import Test.Runner.Html as Runner -- To run this: -- --- cd into part8/test +-- cd into part9/test -- elm-reactor -- navigate to HtmlRunner.elm -main : Program Never +main : Program Never Model Msg main = Runner.run Tests.all