Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ライブで学ぶ The Elm Architecture #meguroes / Meguro ...

y_taka_23
October 10, 2019

ライブで学ぶ The Elm Architecture #meguroes / Meguro ES 23rd

Meguro.es # 23 で使用したスライドです。

当日の形式は、簡単な Elm のサンプルアプリを題材としたライブコーディングです。スライド中にあげたソースコードは、実際には発表中にその場で編集・ビルドしつつ、機能が追加されていく様子をリアルタイムにお見せしました。

イベント概要:https://meguroes.connpass.com/event/140366/

y_taka_23

October 10, 2019
Tweet

More Decks by y_taka_23

Other Decks in Technology

Transcript

  1. 目的特化 AltJS、Elm • Web フロントエンドに特化 ◦ サーバサイドは守備範囲外 • 必要最小限の言語使用 ◦

    Haskell と似ているがかなり機能が絞られている • フレームワークと不可分 ◦ 面倒な部分はすべて隠蔽されている ◦ The Elm Architecture 略して TEA #meguroes
  2. Msg Model Html (rendering) update view #meguroes [ "Initial Message

    2" , "Initial Message 1" ] <ul> <li>Initial Message 2</li> <li>Initial Message 1</li> </ul>
  3. #meguroes type alias Comment = String type alias Model =

    { comments : List Comment } initComments : List Comment initComments = [ "Initial Message 2" , "Initial Message 1" ]
  4. #meguroes view : Model -> Html Msg view model =

    div [] [ h1 [] [ text "Guestbook" ] , input [] [ type_ "text" , placeholder "Message..." ] , button [] [ text "Submit" ] , ul [] <| List.map comment model.comments ] comment : Comment -> Html Msg comment c = li [] [ text c ]
  5. Msg Model Html (rendering) update view #meguroes [ "New Message"

    , "Initial Message 2" , "Initial Message 1" ] [ "Initial Message 2" , "Initial Message 1" ] AddComment "New Message"
  6. #meguroes type Msg = NoOp | AddComment Comment update :

    Msg -> Model -> ( Model, Cmd Msg ) update msg model = case msg of NoOp -> ( model, Cmd.none ) AddComment c -> ( { model | comments = c :: model.comments } , Cmd.none )
  7. #meguroes view : Model -> Html Msg view model =

    div [] [ h1 [] [ text "Guestbook" ] , input [] [ type_ "text" , placeholder "Message..." ] , button [ onClick <| AddComment "New Message" ] [ text "Submit" ] , ul [] <| List.map comment model.comments ]
  8. Msg Model Html (rendering) update view #meguroes [ "Initial Message

    2" , "Initial Message 1" ] SetInput "Current Input" "" "Current Input" [ "Initial Message 2" , "Initial Message 1" ]
  9. Msg Model Html (rendering) update view #meguroes [ "Current Input"

    , "Initial Message 2" , "Initial Message 1" ] [ "Initial Message 2" , "Initial Message 1" ] AddComment "Current Input" ""
  10. #meguroes update : Msg -> Model -> ( Model, Cmd

    Msg ) update msg model = case msg of SetInput c -> ( { model | currentInput = c }, Cmd.none ) AddComment -> ( { model | currentInput = "" , comments = model.currentInput :: model.comments } , Cmd.none )
  11. #meguroes view : Model -> Html Msg view model =

    div [] [ h1 [] [ text "Guestbook" ] , input [] [ type_ "text" , placeholder "Message..." , onInput SetInput , value model.currentInput ] , button [ onClick AddComment ] [ text "Submit" ] , ul [] <| List.map comment model.comments ]