elm: delightful web development

44
delightful web development elm

Upload: amir-barylko

Post on 08-Jan-2017

370 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Elm: delightful web development

delightful webdevelopment

elm

Page 2: Elm: delightful web development

HTML and JS

(so far)

Page 3: Elm: delightful web development

IT’S A FREAKING

MESS!

Page 4: Elm: delightful web development

The ELM

language

Page 5: Elm: delightful web development

Open source

elm-lang.org

Page 6: Elm: delightful web development

Haskell inspired

(and built with)

Page 7: Elm: delightful web development

Functional

Page 8: Elm: delightful web development

Simple

Page 9: Elm: delightful web development

www.elm-tutorial.org

Page 10: Elm: delightful web development

Transpiler

Page 11: Elm: delightful web development

ES3

Page 12: Elm: delightful web development

Web Assembly

Page 13: Elm: delightful web development

Functionsadd : Int -> Int -> Int

add x y =

x + y

Page 14: Elm: delightful web development

Partial Applicationadd2 = add 2

add2 3 -- result 5

Page 15: Elm: delightful web development

Pipe Operator3

|> multiply 2

|> add 1

Page 16: Elm: delightful web development

Type Variablesswitch : ( a, b ) -> ( b, a ) switch ( x, y ) = ( y, x )

Page 17: Elm: delightful web development

Union typestype Answer

= Yes

| No | Other String

type Resource res

= Loading

| Loaded res

Page 18: Elm: delightful web development

Type Aliasestype alias CustomerId = Int

type alias Email = String

Page 19: Elm: delightful web development

Records{ id : Int, name : String}

type alias Player = { id : Int , name : String }

label: Player -> String

Page 20: Elm: delightful web development

Packageshttp://package.elm-lang.org/

Page 21: Elm: delightful web development

elm-lang/coreelmpackages

Page 22: Elm: delightful web development

Maybetype Maybe a = Just a

| Nothing

withDefault : a -> Maybe a -> a

map : (a -> b) -> Maybe a -> Maybe b

Page 23: Elm: delightful web development

Listlength : List a -> Int

head : List a -> Maybe a

tail : List a -> Maybe (List a

filter : (a -> Bool) -> List a

take : Int -> List a -> List a

drop : Int -> List a -> List a

Page 24: Elm: delightful web development

Resulttype Result error value

= Ok value

| Err error

map : (a -> value) -> Result x a -> Result x value

andThen : Result x a -> (a -> Result x b) -> Result x b

Page 25: Elm: delightful web development

elm-lang/htmlelmpackages

Page 26: Elm: delightful web development
Page 27: Elm: delightful web development

Htmltext : String -> Html msg

node: String

-> List (Attribute msg)

-> List (Html msg)

-> Html msg

type alias Html msg = Node msg

type alias Attribute msg = Property msg

Page 28: Elm: delightful web development

Markuph1 : List (Attribute msg) -> List (Html msg) -> Html msg

h2 : List (Attribute msg) -> List (Html msg) -> Html msg

div : List (Attribute msg) -> List (Html msg) -> Html msg

p : List (Attribute msg) -> List (Html msg) -> Html msg

hr : List (Attribute msg) -> List (Html msg) -> Html msg

span : List (Attribute msg) -> List (Html msg) -> Html msg

a : List (Attribute msg) -> List (Html msg) -> Html msg

Page 29: Elm: delightful web development

Small Examplemain =

ul [class "grocery-list"]

[ li [] [text "Pamplemousse"]

, li [] [text "Ananas"]

, li [] [text "Jus d'orange"]

, li [] [text "Boeuf"] , li [] [text "Soupe du jour"]

, li [] [text "Camembert"]

, li [] [text "Jacques Cousteau"]

, li [] [text "Baguette"]

]

•Pamplemousse•Ananas•Jus d'orange•Boeuf•Soupe du jour•Camembert•Jacques Cousteau•Baguette

Page 30: Elm: delightful web development

The ELM

architecture

Page 31: Elm: delightful web development

Modeltype alias Model =

String

init : ( Model, Cmd Msg )

init =

( "Hello", Cmd.none )

Page 32: Elm: delightful web development

Messagestype Msg

= PostToSlack

| FetchSponsors

| NoOp

Page 33: Elm: delightful web development

Viewview : Model -> Html Msg

view model =

div []

[ text model ]

Page 34: Elm: delightful web development

Updateupdate : Msg -> Model -> ( Model, Cmd Msg ) update msg model = case msg of PostToSlack -> Api.sendPost model.email NoOp -> ( model, Cmd.none )

Page 35: Elm: delightful web development

Subscriptionssubscriptions : Model -> Sub Msg subscriptions model =

Sub.none

Page 36: Elm: delightful web development

Mainmain : Program Never

main =

Html.App.program

{ init = init

, view = view , update = update

, subscriptions = subscriptions

}

Page 37: Elm: delightful web development

Expand sample Flow

Page 38: Elm: delightful web development

Examples

Page 39: Elm: delightful web development

Drawbacks

Page 40: Elm: delightful web development

In flux (lightly)

Page 41: Elm: delightful web development

Learn a language

Page 42: Elm: delightful web development

Api still growing

Page 43: Elm: delightful web development

THANK YOU!

Page 44: Elm: delightful web development

[email protected] @abarylko

http://bit.ly/abarylkoslides

http://orthocoders.com

http://westerndevs.com