nelsonic / practice

Practice makes ...
11 stars 4 forks source link

Go Through Elm Guide Examples (Refresher) #16

Closed nelsonic closed 6 years ago

nelsonic commented 6 years ago

I haven't written Elm code in a few months ... 😞 So I'm going through the examples on: https://guide.elm-lang.org to refresh ahead of next week! PDF snapshot at time of writing (when I am doing the exercises): an-introduction-to-elm.pdf

nelsonic commented 6 years ago

I put labeled this issue as in-pogress and then immediately got called away (distracted) for T2h!! 😧

nelsonic commented 6 years ago

"No Runtime Exceptions" ... image LoL! 🤣 But seriously, this is not Elm's fault.

nelsonic commented 6 years ago

Reported issue: https://github.com/evancz/guide.elm-lang.org/issues/118 will update if it happens again, or close if not. 👍

nelsonic commented 6 years ago

https://guide.elm-lang.org Introduction section shows a code for "counter": image

Copied "viewDot" example from: https://youtu.be/jl1tGiUiTtI?t=4m42s

-- Read more about this program in the official Elm guide:
-- https://guide.elm-lang.org/architecture/user_input/buttons.html

import Html exposing (beginnerProgram, div, button, text)
import Html.Events exposing (onClick)

main =
  beginnerProgram { model = 0, view = view, update = update }

view model =
  div []
    [ button [ onClick Decrement ] [ text "-" ]
    , div [] (List.map viewDot (List.range 1 model))
    , button [ onClick Increment ] [ text "+" ]
    ]

viewDot n =
  text "*"

type Msg = Increment | Decrement

update msg model =
  case msg of
    Increment ->
      model + 1

    Decrement ->
      model - 1

image

Easily transforms the counter from a number to a sequence of "dots".

nelsonic commented 6 years ago

Getting the following error: elm-make: Map.!: given key is not an element in the map image

ran:

elm-make buttons-viewdot.elm

Then it works if you visit: http://localhost:8000/examples/index.html image

nelsonic commented 6 years ago

Atom is not cooperating right now ... image

Downloading the latest version of Atom to see if it works: image

Meanwhile using SublimeText ...

nelsonic commented 6 years ago

Still getting the error: image

Recommended remedy https://github.com/elm-lang/elm-package/issues/254#issuecomment-278760570 is: image 1 in 50 (2%) isn't great failure rate ... 🙄

Deleted and re-installed: image

Works: image

nelsonic commented 6 years ago

If you see: I cannot find module 'Svg'.: https://guide.elm-lang.org/architecture/effects/time.html image

elm-package install elm-lang/svg

as per: https://github.com/elm-lang/error-message-catalog/issues/235#issuecomment-325179451

nelsonic commented 6 years ago

https://guide.elm-lang.org/architecture/effects/web_sockets.html

image

I cannot find module 'WebSocket'. 
Module 'Main' is trying to import it. 

Potential problems could be: 
* Misspelled the module name 
* Need to add a source directory or new dependency to elm-package.json 

Install it:

elm-package install elm-lang/websocket
nelsonic commented 6 years ago

https://guide.elm-lang.org/types/reading_types.html image

nelsonic commented 6 years ago

Finished going through all the elm examples for v 0.18 and feel a lot more confident in my elm skills.