Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
JSフレームワークを振り返る
Search
Teruo Kunihiro
February 12, 2017
Programming
0
2.1k
JSフレームワークを振り返る
合同勉強会 in 福岡で発表した資料
https://connpass.com/event/49117/
Teruo Kunihiro
February 12, 2017
Tweet
Share
Other Decks in Programming
See All in Programming
CSC509 Lecture 12
javiergs
PRO
0
160
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
890
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
2
660
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
subpath importsで始めるモック生活
10tera
0
300
Content Security Policy入門 セキュリティ設定と 違反レポートのはじめ方 / Introduction to Content Security Policy Getting Started with Security Configuration and Violation Reporting
uskey512
1
530
現場で役立つモデリング 超入門
masuda220
PRO
15
3.2k
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
【Kaigi on Rails 2024】YOUTRUST スポンサーLT
krpk1900
1
330
Featured
See All Featured
A Modern Web Designer's Workflow
chriscoyier
693
190k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
Automating Front-end Workflow
addyosmani
1366
200k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
Statistics for Hackers
jakevdp
796
220k
It's Worth the Effort
3n
183
27k
How GitHub (no longer) Works
holman
310
140k
Documentation Writing (for coders)
carmenintech
65
4.4k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Transcript
JSϑϨʔϜϫʔΫΛ ৼΓฦΔ IN 2017 2017/02/11 Teruo Kunihiro
➤ ࡢ9݄͔Β גࣜձࣾNulab & Ԭ ➤ ۀ: HTML5ͷCacooͷ։ൃͱ͔ ➤ ࠓ·ͰJS։ൃҊ͕݅ଟ͔ͬͨͷͰओʹJSॻ͍
ͯ·͢ Twitterͱ͔Qiitaͱ͔ͨ·ʹGithub @knhr__ ➤ I love JavaScript!!But I want to study another languages. ࣗݾհ
CACOOʹ͍ͭͯ
͡Ίʹ ϑϩϯτΤϯυʹ͓͍ͯͷॲཧͷϓϩηε Event + DataStore => DOM ͔͠͠DOMͷมͷࡍʹViewʹ߹ΘͤͨDataͷՃ͕ඞཁ Event or
DataStore => DataStore + Data(For View) => DOM ͜ͷॲཧΛղ͘ͷ͕ϑϨʔϜϫʔΫ
͡Ίʹ ➤ ༻ޠ Model = DataStore, DataͷೖΕɺϏδωεϩδοΫ Controller = Πϕϯτड͚ͨΓɺ߹ʹΑͬͯView༻ͷσʔλ
ՃɺEvent Handleɻ ViewModel = View༻ͷσʔλՃɺEventͷϋϯυϦϯάɺσʔ λͷอ࣋ View = ͨͩͷςϯϓϨʔτ, JSXͱ͔ => ͨͩͷݴ༿ͳͷͰదͳ֓೦ͱͯ͠ଊ͑Δ
JSϑϨʔϜϫʔΫԿΛ͍·͔ͨ͠ʁ ➤ Backbone.js ➤ Knockout.js ➤ angular ➤ React ➤
Polymer ➤ riot.js ➤ angular2 ➤ Vue
ͦͷมԽʁ ➤ Componentࢦ ➤ jQueryʹΑΔDOMૢ࡞͔ΒVirtualDOM ➤ Stateཧํ๏ͷมԽ
WEBCOMPONENTͱ ➤ 2011ʹఏҊ͞ΕͨΞΠσΞ ➤ ωΠςΟϒͳAPIݱࡏChormeͷΈʹ࣮͞Ε͍ͯΔ ➤ ༷ࡦఆʹߤ͓ͯ͠Γͣͬ͜͜ͱDraftঢ়ଶ
WEBCOMPONENTͱ DOMͰݴ͑ҎԼͷΑ͏ͳλάΛࢦ͢ <hello-world></hello-world> => <div>hello world</div> DOMɺৼΔ͍ɺState(JS)ɺσβΠϯ(CSS)ɺ(JS)͕ΧϓηϧԽ͞ Εͨλά Data(for View)
+ DOM ϑϩϯτΤϯυͷViewͱಠཱͨ͠ίϯϙʔωϯτͷू߹ମͱଊ͑ Δ͜ͱ͕Ͱ͖Δ
COMPONENTͷ(ͩͬͨ) ➤ DOMͷߋ৽ͷॲཧ͕ॏ͍ DOMؙ͝ͱΛೖΕସ͑ΔͨΊDOMͷߋ৽ॲཧ͕ॏ͔ͬͨɻ ͔͠͠Componentͷߋ৽ҰׅͰߦΘͳ͍ͱෆ߹͕ى͖Δ ࠓ·Ͱͦ͜ΛjQueryͰؤுΔɻ ͘͠Two-way-data-bindingͰؤு͍ͬͯͨ jQueryͰؤுΓͨ͘ͳ͍ɻɻɻ
COMPONENTͷվળ DOMͷߋ৽ΛͰࠩߋ৽(Virtual DOMͳͲʹΑΓ)Ͱߦ͏ϑϨʔϜϫʔΫ͕ ಄͖ͯͨ͠ ࠩߋ৽ϥΠϒϥϦͤʹͰ͖Δ͜ͱʹΑͬͯɺରͷComponentͷߋ৽ ΛҰׅͰߦ͑ΔΑ͏ʹͳͬͨ ͨͩ͠WebComponent࣏తʹ࣮ݱ·ͩ·ͩͬΆ͍ͷͰ֤छϑϨʔϜ ϫʔΫ͕ݸผʹؤு͍ͬͯΔঢ়گ ͳͷͰWebComponentͷํͱׂͱҧ͏ͷ͋ΔɻReactͱ͔ https://github.com/reactjs/react-future/tree/master/02%20-
%20Web%20Components
COMPONENTࢦʹ͍ͭͯ ͰෳͷComponentͲͷΑ͏ʹ࿈ܞ͢Δͷ͔ ࢠͷίϯϙʔωϯτ͕ࢠίϯϙʔωϯτʹରͯ͠σʔλΛྲྀ͠ɺΠϕ ϯτΛड͚औΔΑ͏ʹಈ࡞ͤ͞Δ Component͕૿͑ͨΒঢ়ଶͷཧେมɻɻɻ
ΞϓϦέʔγϣϯͷSTATEཧ ➤ ෳͷComponentͷStateΛݸผʹ࿈ܞͤͯ͞ཧͤ͞Δͷ ݁ߏେม ➤ ͢ΔͱStateཧ·ͨผͰߦ͍͍ͨ!!ͬͯͳΔ ➤ શମͷStateཧݱࡏFluxϥΠΫ(͍͍ͩͨRedux)ͳͷ ͕ओྲྀͱͳ͍ͬͯΔ
STATEͷมભ ➤ MVCϑϨʔϜϫʔΫ ➤ ํόΠϯσΟϯά ➤ Elm / Flux /
Redux ͷΑ͏ͳؔܕϥΠΫͳStateཧ
MVCͱ ➤ Model - ΞϓϦݻ༗ͷσʔλ, ϏδωεϩδοΫ ➤ View - HTML,
ModelͷΛදࣔ ➤ Controller - ViewͷೖྗΛड͚औΔ, ModelΛૢ࡞ View͕ModelΛࢀরͯ͠ඳը͢Δɻ
MVCͱ ➤ ҰํํͳσʔλͷྲྀΕ ➤ ViewModelΛࢹ͍ͯ͠Δ ➤ ControllerΠϕϯτΛड͚ औͬͯModelΛߋ৽͢ΔͷΈ ➤ දతͳϑϨʔϜϫʔΫ
Backbone.js
MVCͱ VitrualDOMҎલͷMVCʹ͍͔͕ͭ͋ͬͨ͘ɻ ➤ DOMঢ়ଶΛอ͍࣋ͯ͠ΔͨΊʹ͠DOMΛશʹ࠶ඳը͢ ΔͱࣦΘΕΔσʔλ͕ଘࡏ͢ΔɻEventListernerͳͲ ➤ DOMͷૢ࡞ͱ͍ͯͨΊʹɺஞҰ࠶ඳըΛߦ͏ͷύ ϑΥʔϚϯεΛ͔ͳΓࣦ͏͜ͱʹͳΓ͏Δ ➤ ࠶ඳըͤͨ͘͞ͳ͍ͷͰɺControllerʹσʔλΛอ࣋ͤͯ͞Ξ
ϓϦέʔγϣϯͷঢ়ଶ͕͙ͪΌ͙ͪΌʹͳͬͨʢମݧஊʣ
MVVMͱ ➤ MVCΛݩʹͨ͠σβΠϯύλʔϯ ➤ ViewΛϏδωεϩδοΫΞϓϦέʔγϣϯͷৼΔ͍͔Β MVCΑΓ໌֬ʹͤ͞Δ ➤ Model - MVCͱಉ͡ɻViewModelͱ݁߹
➤ ViewModel - ModelͱViewͷσʔλͷՃɺσʔλͷอ࣋ ➤ View - ViewModelͱͷ݁߹ɻData-bindings, Event
MVVMͱ ➤ ViewModelͱͷؔ࿈Λ࣋ͨ ͳ͍ɻViewৗʹViewModelͱ ಉظ͢Δ ➤ σʔλͷํҰํํͰͳ͍ ➤ Ͳ͏ΒTwo-way-binding͕͋Δ ͷΛMVVMͱݴͬͯΔͬΆ͍
➤ ComponentࢦʹࣅͯViewʹର ͢ΔStateΛอ࣋͢Δ ➤ දతͳϥΠϒϥϦ Knockout.js
MVVMͱ ➤ όΠσΟϯά͞Ε͍ͯΔσʔλ෦ͷΈͷDOMΛߋ৽͢Δ͜ ͱͰɺMVVMMVCͷஞ࣍શ࠶ඳըͷΛղܾͨ͠ ➤ UI͝ͱʹViewModelΛ࡞͢Ε͍͍ͷͰUIͷฒྻ։ൃΛ؆ ୯ʹͨ͠ʢComponentࢦʣ ͔͠͠MVVMҎԼͷΛҾ͖ى͜͠·ͨ͠ ➤ εςʔτϑϧͳ֊ͷ૿ՃʹΑΓσʔλͷෳࡶ্͕ͬͨ
FLUX(REDUX)ͱ ➤ 2014͝ΖʹFacebook͕ൃදͨ͠Ұํํσʔλϑϩʔ ➤ ؔܕνοΫͳStateཧϑϨʔϜϫʔΫ ➤ ReduxFluxϥΠΫͳσʔλϑϩʔͷछྨͷҰͭ https://facebook.github.io/flux/docs/in-depth-overview.html#content
ͦͯ͠FLUX ➤ React͕ग़͖ͯͯDOMͷஞ࣍ߋ৽ͷίετ͕ݮͬͨ => σʔλͷมߋΛݕؙͯ͠͝ͱViewΛೖΕସ͑ΔॲཧΛؾ ܰʹߦ͑ΔΑ͏ʹͳͬͨ ➤ MVVM(Component)εςʔτϑϧͳ෦Λ૿ͯ͠͠ ·ͬͨ ➤
ͦͯ͠ModelҎ֎εςʔτϨεͳҰํํσʔλϑϩʔͰ͋ ΔMVCతͳΞʔΩςΫνϟ͕ඞཁͱͳͬͨ
TODO MVCΛݟͯΈΑ͏ ➤ TodoͷMVCͷྫΛݟͯݟ·͠ΐ͏
TODO MVCΛݟͯΈΑ͏ ➤ Model͕૿͑Δ ➤ View, Modelͷґଘ͕ؔෳ ࡶʹͳΔ ➤ ༷ʑͳσʔλͷߋ৽ʹରͯ͠
͜ͷΞϓϦέʔγϣϯ༧ଌ Մೳͳঢ়ଶΛҡ࣋Ͱ͖ΔͰ͠ΐ ͏͔
FLUXͳΒ ➤ Storeͷґଘؔ֊ߏʹ อͨΕɺͯ͢ͷStoreͷߋ৽ ͕ߦΘΕΔ·ͰViewʹө͞ Εͳ͍ ➤ StoreΛ৮Δ͜ͱ͕Ͱ͖ͳ ͍ɻಛఆͷAction͔Βৗʹ ಉ݁͡ՌΛಘΔ͜ͱ͕Ͱ͖Δ
ͨΊʹΞϓϦέʔγϣϯͷঢ় ଶΛ༧ଌՄೳʹͰ͖Δ
FLUXͱ ➤ Α͘ݟΔͱMVCͷম͖͠Ͱશ͘৽͍֓͠೦ͱ͍͏͜ͱͰ ͳ͍͕ɺΑΓڧ͍نͰറΒΕΔΠϝʔδ ➤ ΞϓϦέʔγϣϯͷঢ়ଶStoreʢͱComponentʣʹ͚ͩด͡ ࠐΊΒΕΔͨΊʹMVVMͷ࣌ΑΓ༧ଌՄೳͳΞϓϦέʔγϣ ϯ ➤ Stateͷߋ৽ৗʹ
f(State, Actions) => NewState
FLUX(REDUX)ͷ ➤ ݁ߏɻҰͭͷػೳΛՃ͢ΔͨΊʹView࡞ͬͯAction ࡞ͬͯStoreͷߋ৽࡞ͬͯStoreͷใΛComponentʹͭͳ͍Ͱ ͱͨ͘͞ΜͷϑΝΠϧΛฤू͢Δඞཁ͕͋Δɻ ➤ ඇಉظͷॲཧɺFormͷσʔλɺRoutingͷσʔλͳͲΛ্ख͘ ѻ͓͏ͱࢥ͏ͱ͍ΖΜͳϥΠϒϥϦΛೖΕΔ͜ͱʹͳͬͯͱ ʹ͔͘ർΕΔ
ྫ͑REDUX
·ͱΊɾݱঢ় ➤ ίϯϙʔωϯτԽ(WebComponentؔͳ͘)Λߟྀ͞Ε͍ͯ Δ ➤ VirtualDOMతͳDOMΛࠩͰඳըΛߦ͏ͷ͕ଟ͍ ➤ MV*తͳΞϓϩʔν͕ѱ͍Θ͚Ͱͳ͍ ➤ ݱঢ়Reduxʹ͕͋ΔͷͰɺ͍ΖΜͳσʔλϑϩʔͷ
StateཧϑϨʔϜϫʔΫ͕ཚཱ͍ͯ͠Δɻ ➤ ͱ͍͑࠷ۙReduxϥΠΫͳͷ͕ଟ͍ͷͰษڧ͍ͨ͠ਓ ਓ·ͣReduxΛͬͯΈΑ͏!!
༨ஊ(CACOOͷHTML5Խͷ) ➤ HTMLͷViewriotͬͯΔ ➤ riotcomponentࢦͷϑϨʔϜϫʔΫɻVirtualDOMͰͳ ͍͕DOMͷࠩߋ৽Λߦͬͯ͘ΕΔ ➤ StateཧࣗલͰͬͯΔɻComponent͝ͱͷStateͱΞϓϦ શମͷStateΛཧ ➤
ΞϓϦશମͷStateindexedDBʹ֨ೲ͍ͯ͠Δ