Skip to content

Commit a88f354

Browse files
committed
feat!: replace vuex with pinia
It's our latest default recommendations for Vue.js state management. Ref: * <https://twitter.com/VueDose/status/1463169464451706897> * <https://www.reddit.com/r/vuejs/comments/r1vluc/new_default_recommendations/hm3wgbj/>
1 parent 09a3769 commit a88f354

File tree

6 files changed

+39
-18
lines changed

6 files changed

+39
-18
lines changed

index.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async function init() {
4545
// --typescript / --ts
4646
// --jsx
4747
// --router / --vue-router
48-
// --vuex
48+
// --pinia
4949
// --with-tests / --tests / --cypress
5050
// --force (for force overwriting)
5151
const argv = minimist(process.argv.slice(2), {
@@ -61,7 +61,7 @@ async function init() {
6161
// if any of the feature flags is set, we would skip the feature prompts
6262
// use `??` instead of `||` once we drop Node.js 12 support
6363
const isFeatureFlagsUsed =
64-
typeof (argv.default || argv.ts || argv.jsx || argv.router || argv.vuex || argv.tests) ===
64+
typeof (argv.default || argv.ts || argv.jsx || argv.router || argv.pinia || argv.tests) ===
6565
'boolean'
6666

6767
let targetDir = argv._[0]
@@ -79,7 +79,7 @@ async function init() {
7979
// - Project language: JavaScript / TypeScript
8080
// - Add JSX Support?
8181
// - Install Vue Router for SPA development?
82-
// - Install Vuex for state management? (TODO)
82+
// - Install Pinia for state management?
8383
// - Add Cypress for testing?
8484
result = await prompts(
8585
[
@@ -141,9 +141,9 @@ async function init() {
141141
inactive: 'No'
142142
},
143143
{
144-
name: 'needsVuex',
144+
name: 'needsPinia',
145145
type: () => (isFeatureFlagsUsed ? null : 'toggle'),
146-
message: 'Add Vuex for state management?',
146+
message: 'Add Pinia for state management?',
147147
initial: false,
148148
active: 'Yes',
149149
inactive: 'No'
@@ -176,7 +176,7 @@ async function init() {
176176
needsJsx = argv.jsx,
177177
needsTypeScript = argv.typescript,
178178
needsRouter = argv.router,
179-
needsVuex = argv.vuex,
179+
needsPinia = argv.pinia,
180180
needsTests = argv.tests
181181
} = result
182182
const root = path.join(cwd, targetDir)
@@ -212,8 +212,8 @@ async function init() {
212212
if (needsRouter) {
213213
render('config/router')
214214
}
215-
if (needsVuex) {
216-
render('config/vuex')
215+
if (needsPinia) {
216+
render('config/pinia')
217217
}
218218
if (needsTests) {
219219
render('config/cypress')
@@ -230,10 +230,10 @@ async function init() {
230230
render(`code/${codeTemplate}`)
231231

232232
// Render entry file (main.js/ts).
233-
if (needsVuex && needsRouter) {
234-
render('entry/vuex-and-router')
235-
} else if (needsVuex) {
236-
render('entry/vuex')
233+
if (needsPinia && needsRouter) {
234+
render('entry/router-and-pinia')
235+
} else if (needsPinia) {
236+
render('entry/pinia')
237237
} else if (needsRouter) {
238238
render('entry/router')
239239
} else {

snapshot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function createProjectWithFeatureFlags(flags) {
2525
}
2626
}
2727

28-
const featureFlags = ['typescript', 'jsx', 'router', 'vuex', 'with-tests']
28+
const featureFlags = ['typescript', 'jsx', 'router', 'pinia', 'with-tests']
2929

3030
// The following code & comments are generated by GitHub CoPilot.
3131
function fullCombination(arr) {

template/config/pinia/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"pinia": "^2.0.4"
4+
}
5+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { defineStore } from 'pinia'
2+
3+
export const useCounterStore = defineStore({
4+
id: 'counter',
5+
state: () => ({
6+
counter: 0
7+
}),
8+
getters: {
9+
doubleCount: (state) => state.counter * 2
10+
},
11+
actions: {
12+
increment() {
13+
this.counter++
14+
}
15+
}
16+
})
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { createApp } from 'vue'
2+
import { createPinia } from 'pinia'
23
import App from './App.vue'
3-
import store from './store'
44

55
const app = createApp(App)
66

7-
app.use(store)
7+
app.use(createPinia())
88

99
app.mount('#app')
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { createApp } from 'vue'
2-
import App from './App.vue'
2+
import { createPinia } from 'pinia'
33

4+
import App from './App.vue'
45
import router from './router'
5-
import store from './store'
66

77
const app = createApp(App)
88

9+
app.use(createPinia())
910
app.use(router)
10-
app.use(store)
1111

1212
app.mount('#app')

0 commit comments

Comments
 (0)