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

TEA++

 TEA++

TEA で SPA を色々やって遊ぶ

Yosuke Torii

August 25, 2019
Tweet

More Decks by Yosuke Torii

Other Decks in Programming

Transcript

  1. 5&"

  2. 5&" .PEFM 6QEBUF 7JFX 3FEVY /FTUFE$PNQPOFOUT 4UBSU"QQ &⒎FDUT *OUSPEVDF$NE /P/FTUFE$PNQPOFOUT

    /P'31 *OUSPEVDF4VCTDSJQUJPOT FMNTQBFYBNQMF #SPXTFSBQQMJDBUJPO CVJMUJO41"SPVUJOHT 4UBSU"QQ FMNTQBFYBNQMF7 3FBDU)PPLT
  3. 5&" .PEFM 6QEBUF 7JFX 3FEVY /FTUFE$PNQPOFOUT 4UBSU"QQ &⒎FDUT *OUSPEVDF$NE /P/FTUFE$PNQPOFOUT

    /P'31 *OUSPEVDF4VCTDSJQUJPOT FMNTQBFYBNQMF #SPXTFSBQQMJDBUJPO CVJMUJO41"SPVUJOHT 4UBSU"QQ FMNTQBFYBNQMF7 3FBDU)PPLT
  4. "T5IF&MN"SDIJUFDUVSF FNFSHFE JUCFDBNFDMFBSUIBU ZPVDPVMEEPBMNPTUBMMZPVS &MNQSPHSBNNJOHXJUIPVU UIJOLJOHBCPVUTJHOBMTBUBMM4P UIFTUBSUBQQQBDLBHFXBTBO FYQFSJNFOUUPTFFXIBU IBQQFOTXIFOXFQVTITJHOBMT XBZMBUFSJOUIFMFBSOJOHQBUI

    5IFSFTVMUTXFSFHSFBU'PMLT XFSFHFUUJOHTUBSUFERVJDLFS  NBLJOHJUGBSUIFS BOEIBWJOH NPSFGVO*OUIFFOE XFIBE MPUTPGGPMLTXIPCFDBNF FYDFMMFOU&MNQSPHSBNNFST XJUIPVUFWFSSFBMMZMFBSOJOH NVDIBCPVUTJHOBMT5IFZXFSF OPUOFDFTTBSZ 5IF&MN"SDIJUFDUVSF͕ొ৔͢Δ ͱɺ৴߸Λ·ͬͨ͘ߟ͑ͣʹ΄ͱ ΜͲ͢΂ͯͷ&MNϓϩάϥϛϯά Λ࣮ߦͰ͖Δ͜ͱ͕໌Β͔ʹͳΓ ·ͨ͠ɻ͕ͨͬͯ͠ɺTUBSUBQQ ύοέʔδ͸ɺֶशύεͷޙ൒Ͱ γάφϧΛϓογϡͨ͠ͱ͖ʹԿ ͕ى͜Δ͔Λ֬ೝ͢ΔͨΊͷ࣮ݧ Ͱͨ͠ɻ݁Ռ͸ૉ੖Β͔ͬͨ͠Ͱ ͢ʂਓʑ͸ΑΓૣ࢝͘ΊɺΑΓԕ ͘ʹɺͦͯ͠΋ͬͱָ͠ΜͰ͍ ͨʂ࠷ऴతʹ͸ɺγάφϧʹ͍ͭ ͯଟ͘ΛֶͿ͜ͱͳ͘༏लͳ&MN ϓϩάϥϚʔʹͳͬͨଟ͘ͷਓʑ ͕͍·ͨ͠ɻͦΕΒ͸ඞཁ͋Γ· ͤΜͰͨ͠ɻ
  5. 5&" .PEFM 6QEBUF 7JFX 3FEVY /FTUFE$PNQPOFOUT 4UBSU"QQ &⒎FDUT *OUSPEVDF$NE /P/FTUFE$PNQPOFOUT

    /P'31 *OUSPEVDF4VCTDSJQUJPOT FMNTQBFYBNQMF #SPXTFSBQQMJDBUJPO CVJMUJO41"SPVUJOHT 4UBSU"QQ FMNTQBFYBNQMF7 3FBDU)PPLT
  6. 5&" .PEFM 6QEBUF 7JFX 3FEVY /FTUFE$PNQPOFOUT 4UBSU"QQ &⒎FDUT *OUSPEVDF$NE /P/FTUFE$PNQPOFOUT

    /P'31 *OUSPEVDF4VCTDSJQUJPOT FMNTQBFYBNQMF #SPXTFSBQQMJDBUJPO CVJMUJO41"SPVUJOHT 4UBSU"QQ FMNTQBFYBNQMF7 3FBDU)PPLT
  7. 5&" .PEFM 6QEBUF 7JFX 3FEVY /FTUFE$PNQPOFOUT 4UBSU"QQ &⒎FDUT *OUSPEVDF$NE /P/FTUFE$PNQPOFOUT

    /P'31 *OUSPEVDF4VCTDSJQUJPOT FMNTQBFYBNQMF #SPXTFSBQQMJDBUJPO CVJMUJO41"SPVUJOHT 4UBSU"QQ FMNTQBFYBNQMF7 3FBDU)PPLT
  8. 5&" .PEFM 6QEBUF 7JFX 3FEVY /FTUFE$PNQPOFOUT 4UBSU"QQ &⒎FDUT *OUSPEVDF$NE /P/FTUFE$PNQPOFOUT

    /P'31 *OUSPEVDF4VCTDSJQUJPOT FMNTQBFYBNQMF #SPXTFSBQQMJDBUJPO CVJMUJO41"SPVUJOHT 4UBSU"QQ FMNTQBFYBNQMF7 3FBDU)PPLT
  9. module Page.X exposing (..) type alias Model = { ...

    } init : Foo -> Bar -> Model -> (Model, Cmd Msg) update : Baz -> Msg -> Model -> (Model, Cmd Msg, Event) view : Hoge -> Fuga -> Model -> Html Msg -- Main.elm pass concrete args explicitly -- which makes Main.elm dirty! -- -- Also, an extra event should be introduced -- to modify the global state.
  10. module Page.X exposing (..) type alias Model = { session

    : Session , ... } init : Session -> Model -> (Model, Cmd Msg) update : Msg -> Model -> (Model, Cmd Msg) view : Model -> Html Msg -- Main.elm passes session type which contains -- various contexts such as user/credential, -- cached data, etc.
  11. module Main exposing (..) getSession : Page -> Session getSession

    page = case page of FooPage { session } -> session BarPage { session } -> session ... -- Sometimes `setSession` or `updateSession` -- is also needed...
  12. module Page.X exposing (..) type alias Model = { ...

    } init : Session -> Model -> Return Model Msg update : Session -> Msg -> Model -> Return Model Msg view : Session -> Model -> Html Msg
  13. update : Session -> Msg -> Model -> Return Model

    Msg update session msg model = case msg of NoOp -> return model GetUser -> return model |> withTask (Api.getUser GotUser) GotUser user -> return model |> withSession (Session.setUser user session) |> withCommand ... -- There is no `Cmd.none`. -- -- More abstract than (Model, Cmd Msg), easy to -- extend the data structure.
  14. QBDLBHFFMNMBOHPSH FMNTQBFYBNQMF #SPXTFSBQQMJDBUJPO $BDIFJO4FTTJPO -PHJO-PHPVU $SFEFOUJBMT 3PVUFUZQFT $36% 4LFMUPO -PBEJOHTUBUF

    3FUVSO FMNUFBQQ 4IBSFEFSSPS 4FTTJPOJO1BHF 5IFSFBSFOPTJMWFSCVMMFUT 'JOEUIFCFTU5&"GPSZPVSBQQ