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
頑張らないオレオレVuex規約を作った話
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
is_ryo
January 15, 2020
Programming
2.9k
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
頑張らないオレオレVuex規約を作った話
is_ryo
January 15, 2020
More Decks by is_ryo
See All by is_ryo
生成AIとエンジニアの仕事と私~実践知を添えて~
is_ryo
0
120
Unknownのことをちゃんと知りたい_関西フロントエンド忘年会
[email protected]
× KINTOテクノロジーズ
is_ryo
0
47
tRPC入門
is_ryo
1
340
TypeScriptでWebAssemblyに入門しよう
is_ryo
0
390
Honoが良さそう🔥
is_ryo
1
1.4k
LambdaのNodejsをアップデートしたら困った話
is_ryo
2
1.4k
AppSyncで始めるGraphQL
is_ryo
1
650
Other Decks in Programming
See All in Programming
Detecting Compromised CI with eBPF and Cilium Tetragon
lizrice
0
130
Android CLI
fornewid
0
210
2年かけて Deno に DOMMatrix を実装した話 / How I implemented DOMMatrix in Deno over two years
petamoriken
0
200
言語を使う側から、作る側へ。 自作 Lisp で得た新たな気づき。
andpad
0
150
今さら聞けない .NET CLI
htkym
0
180
Prismを使った型安全な暗号化_関数型まつり2026
_fhhmm
0
170
継続モナドとリアクティブプログラミング
yukikurage
3
680
PHP初心者セッション2026 〜生成AIでは見えない裏側を知る:今だからLAMPを通して仕組みを学ぶ〜
kashioka
0
820
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
1
530
AI時代のPHPer生存戦略 ~「言語、もうなんでもよくない?」に本気で向き合う~
vivion
0
230
OpenSpecのproposalにbrainstormingを持たせてみた
tigertora7571
1
200
AI時代に設計が 最大の生産性レバーになる 意図駆動開発とデータを消さない設計|Don't Delete Your Data or Your Intent — Design as the Deepest Lever in the AI Era
tomohisa
1
650
Featured
See All Featured
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
The Cost Of JavaScript in 2023
addyosmani
55
10k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
650
Agile that works and the tools we love
rasmusluckow
331
22k
The Limits of Empathy - UXLibs8
cassininazir
1
580
A designer walks into a library…
pauljervisheath
211
24k
Visualization
eitanlees
152
17k
It's Worth the Effort
3n
188
29k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
290
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
450
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
250
Transcript
頑張らないオレオレ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 便利 • 治安を守るためにはちゃんと規約を作ろう • といっても必要となる規約はどこも違うだろう から参考程度になれば嬉しい
おわり