Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
何でもかんでもStoreにぶち込まないで実装をする話 with Vuex
Search
slont
May 20, 2020
Programming
1.5k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
何でもかんでもStoreにぶち込まないで実装をする話 with Vuex
slont
May 20, 2020
More Decks by slont
See All by slont
SaaS型保険クラウド「Inspire」関連サービス全てをVue.jsで作ってる話
slont
1
1.1k
ぼくのかんがえたさいきょうのVueあーきてくちゃ
slont
9
4k
Other Decks in Programming
See All in Programming
LoopHub - ローカルで動く GitHub で、AI と共同開発
jugyo
1
490
AI に Inclusive UI を書かせよう — Design Rules Skill で Compose UI を作り直す
theoriatec2024
1
470
新人はどこまで自力でやり、どこからAIに頼るべきか/エンジニア育成に向き合う_先輩たちの悩みと知見共有会
toppan_digital_dev
1
590
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
6
3.5k
ALB ログから Trace を気合で繋げる技術
fohte
7
880
Can LLMs Replicate 4 Years of Compose Migration? Exploring the boundaries of automation with 279 XML files from a real product
makun
0
130
週末にAI-DLCを本気で回したら$1,600溶けた
hbashimizu
0
130
ソフトウェアラスタライザ
fadis
1
800
AI駆動開発にグラフDBを重ねてみた
satoshi256kbyte
2
770
巨大モノリシックアプリ モダン化大作戦
ktcryomm
0
440
Claude Codeを組織的に動かして月400PRを実現した話
happy_ryo
0
260
コンパウンドプロダクト開発のためのローカルプロセスマネージャー再発明 #layerxgo
izumin5210
0
660
Featured
See All Featured
Accessibility Awareness
sabderemane
1
210
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
4
620
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.5k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
How to build a perfect <img>
jonoalderson
1
6k
Done Done
chrislema
186
16k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
930
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
570
Building Applications with DynamoDB
mza
96
7.2k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
330
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
1
400
Fashionably flexible responsive web design (full day workshop)
malarkey
408
67k
Transcript
ԿͰ͔ΜͰStoreʹͿͪࠐ· ͳ͍Ͱ࣮Λ͢Δ with Vuex 2020.05.20@PWA Night vol.16
About me • Twitter - @_slont • גࣜձࣾFinatext - Engineer
• Vue.js, Java, Go, Elixir • ࣗ࡞PWA Paroty
https://medium.com/finatext/composition-api-for-vue3-63631dbadcef https://medium.com/finatext/vue-on-ionic%E3%81%A7web
ίτͷൃ
None
શͯStoreͰཧ…ʁ ͍͔ͭഁ͢Δ͜ͱʹݟ͑Δʂʢʁʣ
VuexΛ༻͍ͨ StoreύλʔϯͰͷ࣮Λߟ͑Δ
Vuexͱ • ঢ়ଶཧύλʔϯ + ϥΠϒϥϦ → Flux, ReduxͷྲྀΕΛΉ → αʔυύʔςΟͰӬଓԽՄೳ
• Vueίϯϙʔωϯτ͔Β$storeܦ༝ͰΞΫηεՄೳ → ͜Εάϩʔόϧมͱͯ͠ͷੑ࣭Λ࣋ͭͷͰɺศٓతʹͦ͏ݺͿ ɹ→ ʮάϩʔόϧม͡Όͳ͍ͩΖ͏͕ʂʯͱ͔ݴΘΕ·͕ͨ͠ɺఆٛͰͳ͘ৼΔ͍ͷͳͷͰແࢹ
άϩʔόϧม͕ ԿނΞϯνύλʔͳͷ͔
None
StoreͰͬͪΌ͏ਓͷࢥߟʢໝʣ • ʮάϩʔόϧͬͯதͰείʔϓΛͬͯΔ͔Βେৎʯ → ͋ΔίϯϙʔωϯτείʔϓͰด͡Δ͜ͱ͕Ͱ͖ΔมΛάϩʔόϧʹग़ͯ͠Δ࣌Ͱʢґଘ͕ؔʣີͰ͢ → είʔϓͷωʔϜεϖʔε͕িಥͨ͠ΒऴΘΔ • ʮ݁ہAPIͱ͔άϩʔόϧͳͷͰ·ͱΊͨํ͕ྑ͍ʯ →
ेݸҎ্ͷAPIΛ͏େنͳΞϓϦͩͱstore͕େʹͳͬͯഁ͢Δ → ࢲݟ͕ͩɺstoreͱ͍͏໊લΛ༻ͯ͠͠·ͬͨͷ͕ྑ͘ͳ͔ͬͨ • ʮείʔϓҙࣝ͠ͳͯ͘ྑ͍ͷͰศརʯ → ؒҧ͍ͳ͍ → େنΞϓϦ͡Όͳ͍͔Βʮͨ·ͨ·ʯϝϦοτ͚ͩڗडͰ͖͍ͯΔ͚ͩ • ʮPropsͷόέπϦϨʔ͕ݏͩʯ → Θ͔ΓΈ͕ਂ͍ → ߏԽɾઃܭ্͕ख͘Ͱ͖͍ͯͳ͍Մೳੑ
StoreͰશͯཧύλʔϯ ʢͦΜͳ͜ͱͨ͠ܦݧ͕ͳ͍ͷͰໝʣ
/components/SpecialButton.vue <template> button.button(:disabled=“disabled”) ΞΫγϣϯ <script> computed: { disabled() { return
this.$store.getters[‘page/isDisabled’] } } /store/modules/page.ts state = { canOperate: false, // ૢ࡞ݖݶ hasContent: false // ίϯςϯπ͕͋Δ͔ } getters = { isDisabled(s) { // Ϙλϯ͕ඇ׆ੑ͔ return !(s.canOperate && s.hasContent) } } views ┗ Page.vue // ϖʔδίϯϙʔωϯτ components ┣ Content.vue // Page.vue͔ΒݺΕΔ ┗ SpecialButton.vue // Content.vue͔ΒݺΕΔ store ┣ modules ┣ ┗ page.ts // Page.vueʹؔ͢Δstore ┗ index.ts • disabeldpropsͰ͖͢ → SpecialButton͕storeͷมߋʹґଘ͍ͯ͠Δ • page.tsͷstateʹ֨ೲ͞ΕΔཻ͕ό ϥόϥ → ΄΅࣮֬ʹωʔϜεϖʔεͷίϯϑϦΫτ͕ى͜Δ • ଞʹ৭ʑ͋Δׂ͕Ѫ
Vuex (Store) ΛͲ͏͏ͷ͔
άϩʔόϧมͰ͋Δ͖ͷ & ӬଓԽ • ʮϩάΠϯϢʔβใʯʮઃఆใʯͳͲͷɺجຊతʹߋ৽͕গͳ ͘ɺͲͷίϯϙʔωϯτͰ͍͘͠ճ͢ඞཁ͕͋ΔσʔλΛ֨ೲ → $store.dispatchΛݺΜͰɺaction -> commitͰͦͷ··storeʹ֨ೲͰ͖Δ
-> ΄΅ϫϯϥΠϯͰॻ͚Δ → جຊతʹࢀরͷΈͷσʔλͩͱɺ֤ίϯϙʔωϯτͰͷมߋʹΑΔίϯϑϦΫτ͕ى͜Γʹ͘͘ɺΑΓอकੑ͕ ߴ͘ͳΔ • ӬଓԽ͍ͨ͠σʔλʢvuex-persistedstateʣ → SPAͰɺॳظԽͷσʔλϑΣονͷ࣌ؒΛͰ͖Δ͚ͩॖ͍ͨ͠߹ -> [Local|Session]StorageʹೖΕ͓͍ͯͯɺ ࣍ճΞΫηε࣌ʹσϑΥϧτͰදࣔͰ͖ΔΑ͏ʹͰ͖Δ → ઃఆใͳͲɺAPIΛ࡞ͬͯαʔόͰӬଓԽ͢Δ΄ͲͰͳ͍ͷͰɺLocalStorageӬଓԽ͓ͯ͘͠ͱศར ͜Ε͚ͩʹ͠·͠ΐ͏ʂʂʂ
·ͱΊ StoreύλʔϯΛਖ਼͍͘͜͠ͳͯ͠ UXͷ༏ΕͨΞϓϦΛ࡞Ζ͏ʂ