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
頑張らないオレオレVuex規約を作った話
Search
is_ryo
January 15, 2020
Programming
3k
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
頑張らないオレオレVuex規約を作った話
is_ryo
January 15, 2020
Transcript
28 slides
頑張らないオレオレVuex規約を 作った話 2020/01/15 v-kansai#13 Ryosuke Izumi
Ryosuke Izumi WebApplication / IoT AWS / Vue / TypeScript
/ Serverless v-kansai organizer @is_ryo
Vue 使ってますか?
Vuexって使ってますか?
Vuexってめちゃくちゃ便利ですよね
そう便利…なんだけど……
Vuexの治安悪くなりがち
• 巨大化する State… • 直接呼ばれるmutation… • getters?actions?なにそれおいしいの? • modulesが分けられてない… •
とりあえず Vuex に突っ込んでおくかーみ たいな風潮 • ゴミ箱と化すStore • etc...
None
そうだ。規約を作ろう。
下記3点を解決できるような、かつあんまり頑張 らない規約を作った • Storeの中身を整理したい • 整理した上でComponentがどのStoreを使って いるのかわかりやすくしたい • Storeに Store.hoge
でアクセスしたくない
stores/ 以下にVuex関係の ソースを置く
ディレクトリ構成はこんな感じ src/stores/ ├── module.ts ├── module_2.ts ├── store.ts └── types.d.ts
modulesを切って、それぞ れのModuleファイルを生成 する
Moduleの構成要素は、 namespaced / state / mutations / actions (/ getters)
store.ts
flags.ts(moduleファイル(一部抜粋))
直接 mutations を使わない
• 直接 Store.commit("hoge") って書きたくない • actions 経由で mutations を使う •
Store.dispatch("hogehoge") って書いていく
なぜ action 経由で mutaiton を呼び出すのか? Vuex のドキュメントには「Vuex では全ての mutationは同期的に行うという作法になってい ます」と書いてあって「actionの中では非同期の
操作を行うことができる」となっているので、基 本的に action を経由するようにしている
createNamespacedHelpers を使って、Storeとやり取り する
• というかそもそも Store.hoge って書きたくな い… • あと import Store from
"@/stores/store" と も書きたくない… • せっかく namespace 切ったんだから NamespacedHelpers を使う
None
None
None
まとめ
• NamespacedHelpers 便利 • 治安を守るためにはちゃんと規約を作ろう • といっても必要となる規約はどこも違うだろう から参考程度になれば嬉しい
おわり
More Decks by is_ryo
See All by is_ryo
生成AIとエンジニアの仕事と私~実践知を添えて~
is_ryo
0
140
Unknownのことをちゃんと知りたい_関西フロントエンド忘年会
[email protected]
× KINTOテクノロジーズ
is_ryo
0
55
tRPC入門
is_ryo
1
370
TypeScriptでWebAssemblyに入門しよう
is_ryo
0
410
Honoが良さそう🔥
is_ryo
1
1.5k
LambdaのNodejsをアップデートしたら困った話
is_ryo
2
1.5k
AppSyncで始めるGraphQL
is_ryo
1
670
Other Decks in Programming
See All in Programming
Enforcing Your Architecture with Unit Tests in the AI Era (Swift Connection X)
steliosf
PRO
1
180
Vapor Mode でアクセシビリティは 壊れないか検証した話
fuqda
1
350
止まらない比較を止める — 余帰納法で無限ストリームを比べる
tarao
0
170
学びを記事・スライド・Xへ高速展開する― AI-assisted Learning Loopで回すコンテンツ生成術
ochtum
0
210
Spec-Driven Development - Why Vaadin Is the Perfect Fit
simas
PRO
0
250
Materialが消えた日 〜真っ白なFlutterキャンバスにRenderObjectで絵を描く〜
umigishiaoi
0
160
自作Discord音声botをLambda MicroVMsに移行した話 / Migrating My Discord Voice Bot to Lambda MicroVMs
akihisaikeda
1
330
地方こそサーバーレス — 10年続けた、顔が見えるチームで確かな基盤を / Serverless Matters Most in Regional Areas — 10 Years of Building Reliable Foundations with Close-Knit Teams
seike460
PRO
1
460
どうしても Eloquent でリポジトリパターンをやりたいんだ #phpcon_niigata / phpcon-niigata-2026
shogogg
0
310
조합이폭발하는디자인시스템이걸눈으로도테스트하라고요
giljongyu
0
750
社内AIエージェント「Askワンバン」における コストチューニングの取り組み
t0yohei
0
170
私なりのハーネスエンジニアリング ~独自の言語処理系の開発を通して~
seosoft
0
210
Featured
See All Featured
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
600
So, you think you're a good person
axbom
PRO
2
2.3k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
610
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
4
1.3k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
480
The Pragmatic Product Professional
lauravandoore
37
7.5k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
68
60k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
Making Projects Easy
brettharned
120
6.9k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
980
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.7k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
620