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
何でもかんでも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
「なぜそう決めたのか」を残し続ける仕組み ― Notion AI カスタムエージェント × Slack連携による設計判断の自動記録 - NIKKEI Tech Talk #47
niftycorp
PRO
0
170
依存関係から依存物へ―Dependencyという言葉の歴史をひも解く
j_lee
0
120
Contextとはなにか
chiroruxx
1
320
Observability in Practice:Grafana 與 Edge Device SRE 的那些事
blueswen
0
160
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.4k
Signal Forms: Details & Live Coding @enterJS 2026 in Mannheim
manfredsteyer
PRO
0
130
dRuby over BLE
makicamel
2
340
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
250
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
7
4.4k
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
670
OSもどきOS
arkw
0
560
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
310
Featured
See All Featured
Scaling GitHub
holman
464
140k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
580
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.5k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
240
WENDY [Excerpt]
tessaabrams
11
38k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
230
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
Mobile First: as difficult as doing things right
swwweet
225
10k
KATA
mclloyd
PRO
35
15k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
410
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
570
Designing for humans not robots
tammielis
254
26k
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ͷ༏ΕͨΞϓϦΛ࡞Ζ͏ʂ