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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
Transcript
16 slides
ԿͰ͔ΜͰ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ͷ༏ΕͨΞϓϦΛ࡞Ζ͏ʂ
More Decks by slont
See All by slont
SaaS型保険クラウド「Inspire」関連サービス全てをVue.jsで作ってる話
slont
1
1.1k
ぼくのかんがえたさいきょうのVueあーきてくちゃ
slont
9
4.1k
Other Decks in Programming
See All in Programming
Scalaの型でマルチテナントの認可を守る
nextbeatdev
0
160
ローカルLLMの基本と近況 2611 / Local LLM basics and recent situation 2611
kishida
3
590
Claude Codeのおかげでやりたいことがやれるようになったんだよォー!
sms_tech
0
150
[DroidKnights 2026] Workflow AX 적용기 — 자동 정책 정리부터 E2E까지
dayeon
0
110
ビジネスロジックを堅牢に~Scala 3のドメインプリミティブ~
j5ik2o
0
200
React Native経験者が Flutterを30⽇間触って驚いたこと
3saito
0
200
学びを記事・スライド・Xへ高速展開する― AI-assisted Learning Loopで回すコンテンツ生成術
ochtum
0
210
Coding with AI: How to trust the storyteller (AWS Community Day Adria, Ljubljana 2026)
slobodan
0
150
コード生成時代のAPI定義を支えるRequest Spec移行
pvcresin
0
280
느린 네트워크와 저사양 디바이스 사용자를 위한 웹뷰 로딩 시간 개선기
kmkim
1
250
AIが実装を担う時代の「技術設計」と「チームマネジメント」
kamina_zzz
2
280
私なりのハーネスエンジニアリング ~独自の言語処理系の開発を通して~
seosoft
0
220
Featured
See All Featured
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
6
940
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Prompt Engineering for Job Search
mfonobong
0
590
Joys of Absence: A Defence of Solitary Play
codingconduct
1
580
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.4k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
12k
It's Worth the Effort
3n
188
29k
How STYLIGHT went responsive
nonsquared
100
6.4k
Color Theory Basics | Prateek | Gurzu
gurzu
1
530
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
330
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
640