Elm Friendly functional frontend
Light · Postcard
102 × 152 mm · PDF
Dark · Postcard
102 × 152 mm · PDF
Ink saver · Postcard
102 × 152 mm · PDF
Light · A4 landscape
297 × 210 mm · PDF
Dark · A4 landscape
297 × 210 mm · PDF
Ink saver · A4 landscape
297 × 210 mm · PDF
Light · A3 landscape
420 × 297 mm · PDF
Dark · A3 landscape
420 × 297 mm · PDF
Ink saver · A3 landscape
420 × 297 mm · PDF
Start here
elm initelm reactorelm make src/Main.elm
elm make src/Main.elm --output=elm.js
elm install <author/package>
elm replelm make src/Main.elm --optimize --output=elm.js
elm-testConcepts
- Model all state
- View Html Msg
- Msg what happened
- Update returns new Model
Project
elm initelm install <author/package>
elm replelm repl --no-colors
elm repl --interpreter=<path>
elm <command> --help
elm --versionBuild
elm make src/Main.elm
elm make src/Main.elm --output=elm.js
elm make src/Main.elm --optimize
elm make src/Main.elm --debug
elm make src/Main.elm --output=/dev/null
elm make src/A.elm src/B.elm --output=elm.js
elm make src/Main.elm --report=json
elm make --docs=docs.json
elm reactorelm reactor --port=<n>
Packages
elm publishelm bumpelm diffelm diff <author/package> <v1> <v2>
elm install elm/json
elm install elm/http
elm install elm/browser
elm install elm/url
elm install elm/time
elm install elm/random
Tooling
elm-format src/ --yes
elm-format src/ --validate
elm-format --stdin
elm-test initelm-testelm-test <file>
elm-test --watch
elm-test --fuzz <n>
elm-test --seed <n>
elm-test install <author/package>
elm-reviewSyntax
module Main exposing (main)
import Html exposing (Html, div, text)
import Html.Attributes as A
name : Int -> String
type alias User = { name : String }
type Msg = Inc | Dec
type Maybe a = Just a | Nothing
case x of ... -> ...
if a then b else c
let y = 1 in y + 1
\x -> x + 1
{ model | count = 1 }
model.count / .count
x |> f |> g
f << g / f >> g
(a, b) / ( a, b, c )
-- note / {- block -}
"""multi line"""
Core library
List.map f xsList.filter f xs
List.foldl f init xs
String.fromInt n / String.toInt s
Maybe.withDefault 0 m
Maybe.map f mResult.map f rDict.fromList pairs
Dict.get key dDebug.log "label" value
Debug.todo "msg"
Programs
Browser.sandboxBrowser.elementBrowser.document
Browser.application
Cmd.none / Sub.none
Http.get { url = u, expect = e }
Decode.field "name" Decode.string
Html.Events.onClick Msg
Html.Events.onInput Msg
port sendOut : String -> Cmd msg
| Function | Effects | Use for |
|---|---|---|
sandbox |
none | Learning, toys |
element |
Cmd, Sub | Widget in a page |
document |
Cmd, Sub | Own title and body |
application |
Cmd, Sub, URL | Single-page app |
Recipes
module Main exposing (main)import Browserimport Html exposing (button, div, text)import Html.Events exposing (onClick)main = Browser.sandbox { init = 0, update = update, view = view }type Msg = Inc | Decupdate msg n = case msg of Inc -> n + 1 Dec -> n - 1view n = div [] [ button [ onClick Dec ] [ text "-" ] , text (String.fromInt n) , button [ onClick Inc ] [ text "+" ] ]
# elm make src/Main.elm --output=elm.js<div id="app"></div><script src="elm.js"></script><script> Elm.Main.init({ node: document.getElementById('app') })</script>
import Json.Decode as Dtype alias User = { name : String, age : Int }userDecoder : D.Decoder UseruserDecoder = D.map2 User (D.field "name" D.string) (D.field "age" D.int)
elm make src/Main.elm --optimize --output=elm.jsnpx terser elm.js --compress --mangle -o elm.min.js



