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
頑張らないオレオレVuex規約を作った話
is_ryo
January 15, 2020
More Decks by is_ryo
See All by is_ryo
生成AIとエンジニアの仕事と私~実践知を添えて~
is_ryo
0
110
Unknownのことをちゃんと知りたい_関西フロントエンド忘年会
[email protected]
× KINTOテクノロジーズ
is_ryo
0
42
tRPC入門
is_ryo
1
320
TypeScriptでWebAssemblyに入門しよう
is_ryo
0
360
Honoが良さそう🔥
is_ryo
1
1.3k
LambdaのNodejsをアップデートしたら困った話
is_ryo
2
1.4k
AppSyncで始めるGraphQL
is_ryo
1
640
Other Decks in Programming
See All in Programming
JCON - Create Agentic AI Apps, The Easy Way!
kdubois
1
100
検索設計から 推論設計への重心移動と Recall-First Retrieval
po3rin
5
1.6k
Kubernetesを使わない環境にもCloud Nativeなデプロイを実現する / Enabling Cloud Native deployments without the complexity of Kubernetes
linyows
3
360
開発とはなにか、Essenceカーネルで見えるもの
ukin0k0
0
110
Agentic Elixir
whatyouhide
0
450
サークル参加から学ぶ、小さな事業の回し方
yuzneri
0
160
Programming with a DJ Controller — not vibe coding
m_seki
3
810
Lightning-Fast Method Calls with Ruby 4.1 ZJIT / RubyKaigi 2026
k0kubun
3
2.7k
GitHubCopilotCLIをはじめよう.pdf
htkym
0
330
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
300
Agentic UI in the Frontend: Architectures with Open Standards @JAX 2026 in Mainz
manfredsteyer
PRO
0
110
ソフトウェア設計の結合バランス #phperkaigi
kajitack
0
500
Featured
See All Featured
So, you think you're a good person
axbom
PRO
2
2k
エンジニアに許された特別な時間の終わり
watany
106
240k
Marketing to machines
jonoalderson
1
5.2k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
300
Paper Plane (Part 1)
katiecoart
PRO
0
7.3k
Raft: Consensus for Rubyists
vanstee
141
7.4k
What does AI have to do with Human Rights?
axbom
PRO
1
2.1k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
30 Presentation Tips
portentint
PRO
1
290
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
240
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
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 便利 • 治安を守るためにはちゃんと規約を作ろう • といっても必要となる規約はどこも違うだろう から参考程度になれば嬉しい
おわり