Slide 1

Slide 1 text

Rethink React in Elm LY @ Modernweb 2016

Slide 2

Slide 2 text

LY Appier yhsiang elm.tw

Slide 3

Slide 3 text

The History of programming from Let’s be mainstream! User focused design in Elm Assembly

Slide 4

Slide 4 text

The History of programming Assembly C from Let’s be mainstream! User focused design in Elm

Slide 5

Slide 5 text

The History of programming Assembly C Java from Let’s be mainstream! User focused design in Elm

Slide 6

Slide 6 text

The History of programming Assembly C Java Javascript from Let’s be mainstream! User focused design in Elm

Slide 7

Slide 7 text

The History of programming Assembly C Java Javascript Maintainability from Let’s be mainstream! User focused design in Elm

Slide 8

Slide 8 text

The History of programming Assembly C Java Javascript Maintainability Memory
 Management from Let’s be mainstream! User focused design in Elm

Slide 9

Slide 9 text

The History of programming Assembly C Java Javascript Maintainability Memory
 Management All those
 freakin’ types from Let’s be mainstream! User focused design in Elm

Slide 10

Slide 10 text

The History of programming Assembly C Java Javascript Maintainability Memory
 Management All those
 freakin’ types Maintainability from Let’s be mainstream! User focused design in Elm

Slide 11

Slide 11 text

https://www.flickr.com/photos/sorbus/2503348546

Slide 12

Slide 12 text

What is Elm? • Language for making UI • functional • static type • strong type • ML family • Framework • Elm Architecture

Slide 13

Slide 13 text

Elm tools • http://elm-lang.org/install • brew cask install elm-platform • elm-make • elm-package • elm-reactor • elm-repl • now version: 0.17

Slide 14

Slide 14 text

Elm package • http://package.elm-lang.org/ • namespace • API Design Guidelines

Slide 15

Slide 15 text

Elm syntax • http://elm-lang.org/try • comment: --, {- -} • char: ‘a’ • string: “abc” • if … then … else • case .. of 
 a -> doSomething
 b -> — single line comment {- 
 multi line comment
 -} achar = ‘a’ astring = “abc” isEven number = if number % 2 == 0 then True else False

Slide 16

Slide 16 text

Elm style guideline • http://elm-lang.org/docs/style-guide • homeDirectory = “/root/files”
 ->
 homeDirectory = 
 “/root/files” • type Skill
 = Code
 | Sleep
 | Argue • elm-format

Slide 17

Slide 17 text

Elm syntax more… • add : Int -> Int -> Int • add x y = x + y • \n -> n + 1 • let .. in • type Tree =
 Branch | Leaf evenFilter data = let isEven number = if number % 2 == 0 then True else False in List.filter isEven data

Slide 18

Slide 18 text

Elm data structure • List • Array • Set • Tuple • Dict • Record > data = [1, 2, 2, 3] [1,2,2,3] : List number > Array.fromList data Array.fromList [1,2,2,3] : Array.Array number > Set.fromList data Set.fromList [1,2,3] : Set.Set number > type Animal = Cat | Mouse > tom = (“Tom”, Cat) > animals = [tom, (“Jerry”, Mouse)] > Dict.fromList animals Dict.fromList [(“Jerry”,Mouse),(“Tom”,Cat)] : Dict.Dict String Repl.Animal > person = { name = “LY”, gender = “male” } { name = “LY, gender = “male” } : { gender : String, name : String }

Slide 19

Slide 19 text

https://www.flickr.com/photos/anderoo/3338275165

Slide 20

Slide 20 text

Be Direct pure function easy to reason about safe monad from Let’s be mainstream! User focused design in Elm

Slide 21

Slide 21 text

Be Direct pure function stateless function easy to reason about safe monad from Let’s be mainstream! User focused design in Elm

Slide 22

Slide 22 text

Be Direct pure function stateless function easy to reason about easy to refactor safe monad from Let’s be mainstream! User focused design in Elm

Slide 23

Slide 23 text

Be Direct pure function stateless function easy to reason about easy to refactor safe reliable monad from Let’s be mainstream! User focused design in Elm

Slide 24

Slide 24 text

Be Direct pure function stateless function easy to reason about easy to refactor safe reliable monad “callbacks” from Let’s be mainstream! User focused design in Elm

Slide 25

Slide 25 text

Be Direct andThen : Maybe a -> (a -> Maybe b) -> Maybe b andThen maybe callback = case maybe of Just value -> callback value Nothing -> Nothing from Let’s be mainstream! User focused design in Elm

Slide 26

Slide 26 text

Elm Architecture

Slide 27

Slide 27 text

Elm Architecture type alias Model = Int type Msg = Inc | Dec update : Msg -> Model -> Model update msg model = case msg of Inc -> model + 1 Dec -> model - 1 view : Model -> Html Msg view model = div [] [ button [onClick Inc] [text “+”] , text (toString model) , button [onClick Dec] [text “-“] ]

Slide 28

Slide 28 text

Communicate with JS • Native Modules • note by poying • _{github_user_name}${github_repo_name}$ {module_name}

Slide 29

Slide 29 text

Native module //Native/DateTime.js var _gdotdesign$elm_ui$Native_DateTime = function() { function now() { return new Date() } … return { …, now: now } }() — Ext/Date.elm import Native.DateTime now : a -> Date.Date now _ = Native.DateTime.now Nothing

Slide 30

Slide 30 text

Communicate with JS • JavaScript Interop: Port • message

Slide 31

Slide 31 text

Ports // app.js var app = Elm.Spelling.fullscreen(); app.ports.check.subscribe(function(word) { var suggestions = spellCheck(word); app.ports.suggestions.send(suggestions); }); — Spelling.elm port module Spelling exposing (..) port check : String -> Cmd msg port suggestions : (List String -> msg) -> Sub msg

Slide 32

Slide 32 text

Elm Recent • How to use at work • http://elm-lang.org/blog/how-to-use-elm-at-work • elm-html • Html.Keyed

Slide 33

Slide 33 text

Elm Future • Server-side render • Improved elm-reactor • Shuffling some Html functions
 • Removing Backticks / Flipping andThen something `andThen` doSomething => something |> andThen doSomething Html.App move to Html

Slide 34

Slide 34 text

What about React? pattern ES2015 class functional null

Slide 35

Slide 35 text

What about React? pattern ES2015 class functional null component folder

Slide 36

Slide 36 text

What about React? pattern ES2015 class functional null component folder less inheritance

Slide 37

Slide 37 text

What about React? pattern ES2015 class functional null component folder less inheritance recompose

Slide 38

Slide 38 text

What about React? pattern ES2015 class functional null component folder less inheritance recompose null-input-value-prop

Slide 39

Slide 39 text

We are HIRING [email protected]