Share
Embed
Elmが思ったより良かった話
nagimaru
June 19, 2019
Transcript
19 slides
-
2019/6/19 PWANight localhost:8080 6/19 TEAとは Update Msgを受け取り、新しいModelとCmdを返す Model 状態 View
Modelを元にHTMLを返す Cmd 副作⽤を扱う仕組み。APIのレスポンスなどをMsgと共に返してくれたり。 -
2019/6/19 PWANight localhost:8080 7/19 TEAとは Model init : String ->
( Model, Cmd Msg ) init slug = getArticle slug -- ① slug と共にGetArticle というMsg を送信 getArticle : String -> ( Model, Cmd Msg ) getArticle slug = update (GetArticle slug) { response = Loading, slug = slug } -
2019/6/19 PWANight localhost:8080 8/19 TEAとは Update update : Msg ->
Model -> ( Model, Cmd Msg ) update msg model = case msg of -- ③ Cmd が返したGotArticle というMsg と共に結果を受け取りモデル更新 GotArticle result -> case result of Ok articleData -> ( { model | response = Success articleData }, Cmd.none ) Err _ -> ( { model | response = Failure }, Cmd.none ) -- ② GetArticle を受け取ったらContentfulAPI を呼び出す(Cmd 発⾏) GetArticle slug -> ( model, Contentful.getArticle GotArticle slug ) -
2019/6/19 PWANight localhost:8080 9/19 TEAとは View view : Model ->
{ title : String, body : List (Html Msg) } view model = { title = "Hoge" , body = [ section [ ] [ case model.response of Loading -> p [ ] [ text "Loading..." ] Failure -> p [ ] [ text "Not Found" ] Success articleData -> -- TODO: 記事表⽰ article [ ] [ ] ] ] } -
2019/6/19 PWANight localhost:8080 11/19 Elmのいいところ 基本的に実⾏時エラーが出ない 仕様が⼩さいため学習コストが極めて低い [1,2,3]===[1,2,3] がTrue *1
コンパイル早え エラーメッセージが親切すぎる 型付けに「がんばる」とか「がんばらない」とかない*2 *1 参照を考えなくて良い *2 「がんばらないTypeScript」が話題でしたね -
2019/6/19 PWANight localhost:8080 13/19 個⼈的な使い分け ハッカソンなどの使い捨てプロダクト JavaScript + React +
MobX 普段の業務 TypeScript + React + (MobX or Typeless) ⼤規模開発 TypeScript + Angular + NgRx (angular-cliが⼼強い) とにかく堅牢に⾏きたい Elm + The Elm Architecture -
2019/6/19 PWANight localhost:8080 16/19 PWA with Elm $ create-elm-app pwa_app
これだけでPWA対応したコードが吐き出されます