Skip to content

Commit

Permalink
Merge branch 'vuejs:v2' into v2
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackCrowxyz authored Sep 26, 2023
2 parents 17634a5 + 498cff1 commit 98b46fe
Show file tree
Hide file tree
Showing 212 changed files with 14,903 additions and 9,397 deletions.
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ body:
attributes:
label: Describe alternatives you've considered
description: A clear and concise description of any alternative solutions or features you've considered.
- type: markdown
attributes:
value: |
## Before creating a feature request make sure that:
- This hasn't been [requested before](https://github.com/vuejs/pinia/issues).
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
- 'packages/docs/**'
- 'packages/playground/**'
pull_request:
branches: v2
paths-ignore:
- 'packages/docs/**'
- 'packages/playground/**'
Expand All @@ -16,18 +17,17 @@ jobs:

steps:
- uses: actions/checkout@v3
- uses: pnpm/[email protected]
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
with:
version: 6.32.1
- uses: actions/setup-node@v2
with:
node-version: '16'
node-version: 18
cache: 'pnpm'

- run: pnpm install
- run: pnpm run lint
- run: pnpm run test:types
- run: pnpm run test:jest
- run: pnpm run -r dev:prepare
- run: pnpm run test:vitest
- run: pnpm run build
- run: pnpm run build:dts
- run: pnpm run test:dts
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ docs-api
packages/docs/api
.yalc
yalc.lock
.idea
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__build__
dist
coverage
69 changes: 39 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
- 🔌 Extensible
- 🏗 Modular by design
- 📦 Extremely light
- ⛰️ Nuxt Module

Pinia works both for Vue 2.x and Vue 3.x. It requires Vue 2 with the latest `@vue/composition-api` or Vue `^3.2.0-0`.
Pinia works with both Vue 2 and Vue 3.

Pinia is the most similar English pronunciation of the word _pineapple_ in Spanish: _piña_. A pineapple is in reality a group of individual flowers that join together to create a multiple fruit. Similar to stores, each one is born individually, but they are all connected at the end. It's also a delicious tropical fruit indigenous to South America.

Expand All @@ -37,16 +38,6 @@ Pinia is the most similar English pronunciation of the word _pineapple_ in Spani

<!--sponsors start-->

<h4 align="center">Gold Sponsors</h4>
<p align="center">
<a href="https://vuejobs.com/?utm_source=vuerouter&utm_campaign=sponsor" target="_blank" rel="noopener noreferrer">
<picture>
<source srcset="https://posva-sponsors.pages.dev/logos/vuejobs.svg" media="(prefers-color-scheme: dark)" height="72px" alt="VueJobs" />
<img src="https://posva-sponsors.pages.dev/logos/vuejobs.svg" height="72px" alt="VueJobs" />
</picture>
</a>
</p>

<h4 align="center">Silver Sponsors</h4>
<p align="center">
<a href="https://www.vuemastery.com/" target="_blank" rel="noopener noreferrer">
Expand All @@ -71,7 +62,7 @@ Pinia is the most similar English pronunciation of the word _pineapple_ in Spani
<img src="https://avatars.githubusercontent.com/u/2486424?u=7b0c73ae5d090ce53bf59473094e9606fe082c59&v=4" height="26px" alt="Stanislas Ormières" />
</picture>
</a>
<a href="www.vuejs.de" target="_blank" rel="noopener noreferrer">
<a href="https://www.vuejs.de" target="_blank" rel="noopener noreferrer">
<picture>
<source srcset="https://avatars.githubusercontent.com/u/4183726?u=6b50a8ea16de29d2982f43c5640b1db9299ebcd1&v=4" media="(prefers-color-scheme: dark)" height="26px" alt="Antony Konstantinidis" />
<img src="https://avatars.githubusercontent.com/u/4183726?u=6b50a8ea16de29d2982f43c5640b1db9299ebcd1&v=4" height="26px" alt="Antony Konstantinidis" />
Expand All @@ -85,8 +76,8 @@ Pinia is the most similar English pronunciation of the word _pineapple_ in Spani
</a>
<a href="https://nuxtjs.org" target="_blank" rel="noopener noreferrer">
<picture>
<source srcset="https://posva-sponsors.pages.dev/logos/nuxt-dark.svg" media="(prefers-color-scheme: dark)" height="26px" alt="NuxtJS" />
<img src="https://posva-sponsors.pages.dev/logos/nuxt-light.svg" height="26px" alt="NuxtJS" />
<source srcset="https://posva-sponsors.pages.dev/logos/nuxt-dark.svg" media="(prefers-color-scheme: dark)" height="26px" alt="Nuxt Labs" />
<img src="https://posva-sponsors.pages.dev/logos/nuxt-light.svg" height="26px" alt="Nuxt Labs" />
</picture>
</a>
</p>
Expand All @@ -107,22 +98,14 @@ A few notes about the project and possible questions:

**A**: Dynamic modules are not type safe, so instead [we allow creating different stores](https://pinia.vuejs.org/cookbook/composing-stores.html) that can be imported anywhere

## Roadmap / Ideas

- [x] Should the state be merged at the same level as actions and getters?
- [ ] ~~Allow grouping stores together into a similar structure and allow defining new getters (`pinia`)~~
You can directly call `useOtherStore()` inside of a getter or action.
- [ ] ~~Getter with params that act like computed properties (@ktsn)~~ Can be implement through a custom composable and passed directly to state.

## Installation

```bash
yarn add pinia
# or with npm
# or pnpm or yarn
npm install pinia
```

If you are using Vue 2, make sure to install latest `@vue/composition-api`:
If you are using Vue <2.7, make sure to install latest `@vue/composition-api`:

```bash
npm install pinia @vue/composition-api
Expand All @@ -135,11 +118,37 @@ npm install pinia @vue/composition-api
Create a pinia (the root store) and pass it to app:

```js
// Vue 3
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'

const pinia = createPinia()
const app = createApp(App)

app.use(createPinia())
app.use(pinia)
app.mount('#app')
```

```js
// Vue 2
import { createPinia, PiniaVuePlugin } from 'pinia'

Vue.use(PiniaVuePlugin)
const pinia = createPinia()

new Vue({
el: '#app',
// other options...
// ...
// note the same `pinia` instance can be used across multiple Vue apps on
// the same page
pinia,
})
```

For more detailed instructions, including [Nuxt configuration](https://pinia.vuejs.org/ssr/nuxt.html#nuxt-js), check the [Documentation](https://pinia.vuejs.org).

### Create a Store

You can create as many stores as you want, and they should each exist in different files:
Expand All @@ -158,10 +167,10 @@ export const useMainStore = defineStore('main', {
// optional getters
getters: {
// getters receive the state as first parameter
doubleCount: (state) => state.counter * 2,
doubleCounter: (state) => state.counter * 2,
// use getters in other getters
doubleCountPlusOne(): number {
return this.doubleCount + 1
doubleCounterPlusOne(): number {
return this.doubleCounter + 1
},
},
// optional actions
Expand All @@ -185,14 +194,14 @@ export default defineComponent({
const main = useMainStore()

// extract specific store properties
const { counter, doubleCount } = storeToRefs(main)
const { counter, doubleCounter } = storeToRefs(main)

return {
// gives access to the whole store in the template
main,
// gives access only to specific state or getter
counter,
doubleCount,
doubleCounter,
}
},
})
Expand Down
37 changes: 0 additions & 37 deletions jest.config.js

This file was deleted.

5 changes: 1 addition & 4 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
[build.environment]
NPM_FLAGS="--version"

[build]
command = "npx pnpm@6 i --store=node_modules/.pnpm-store && npx pnpm@6 run docs:build"
command = "pnpm run docs"
ignore = "./scripts/docs-check.sh"
publish = "packages/docs/.vitepress/dist"
71 changes: 36 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@pinia/root",
"packageManager": "[email protected]",
"private": true,
"workspaces": [
"packages/*"
Expand All @@ -8,57 +9,54 @@
"release": "node scripts/release.mjs",
"size": "pnpm run -r size",
"build": "pnpm run -r build",
"docs:build": "pnpm run docs:api && pnpm run -r docs:build --filter ./packages/docs",
"docs": "pnpm run docs:api && pnpm run --filter ./packages/docs -r docs:build",
"play": "pnpm run -r play",
"build:dts": "pnpm run -r --parallel build:dts",
"lint": "prettier -c --parser typescript \"packages/*/{src,__tests__,e2e}/**/*.[jt]s?(x)\"",
"lint": "prettier -c --parser typescript \"packages/*/{src,__tests__,e2e}/**/*.[jt]s?(x)\" \"packages/docs/**/*.[jt]s\"",
"lint:fix": "pnpm run lint --write",
"test": "pnpm run test:types && pnpm run test:jest && pnpm run -r test && pnpm run build && pnpm run build:dts && pnpm test:dts",
"test:jest": "jest --coverage",
"test": "pnpm run -r dev:prepare && pnpm run test:types && pnpm run test:vitest run && pnpm run -r test && pnpm run build && pnpm run build:dts && pnpm test:dts",
"test:vitest": "vitest --coverage",
"test:types": "tsc --build ./tsconfig.json",
"test:dts": "pnpm run -r test:dts",
"docs:api": "pnpm run -r docs:api --filter ./packages/docs"
"docs:api": "pnpm run --filter ./packages/docs -r docs:api"
},
"devDependencies": {
"@rollup/plugin-alias": "^3.1.9",
"@rollup/plugin-commonjs": "^22.0.1",
"@rollup/plugin-node-resolve": "^13.3.0",
"@rollup/plugin-replace": "^4.0.0",
"@sucrase/jest-plugin": "^2.2.1",
"@types/jest": "^28.1.4",
"@rollup/plugin-alias": "^5.0.0",
"@rollup/plugin-commonjs": "^24.1.0",
"@rollup/plugin-node-resolve": "^15.0.2",
"@rollup/plugin-replace": "^5.0.2",
"@rollup/plugin-terser": "^0.4.1",
"@types/lodash.kebabcase": "^4.1.7",
"@types/node": "^16.11.41",
"@vue/compiler-sfc": "^3.2.37",
"@vue/server-renderer": "^3.2.37",
"chalk": "^4.1.2",
"@types/node": "^18.15.11",
"@vitest/coverage-v8": "^0.32.4",
"@vue/compiler-sfc": "^3.3.4",
"@vue/server-renderer": "^3.3.4",
"chalk": "^5.2.0",
"conventional-changelog-cli": "^2.2.2",
"enquirer": "^2.3.6",
"execa": "^6.1.0",
"expect": "^28.1.1",
"globby": "^12.2.0",
"jest": "^28.1.2",
"jest-environment-jsdom": "^28.1.2",
"jest-mock-warn": "^1.1.0",
"lint-staged": "^12.5.0",
"execa": "^7.1.1",
"globby": "^13.1.4",
"happy-dom": "^9.18.3",
"lint-staged": "^13.2.2",
"lodash.kebabcase": "^4.1.1",
"minimist": "^1.2.6",
"minimist": "^1.2.8",
"p-series": "^3.0.0",
"pascalcase": "^1.0.0",
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"rollup": "^2.75.7",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.31.2",
"semver": "^7.3.7",
"typedoc": "^0.22.15",
"typedoc-plugin-markdown": "^3.12.1",
"typescript": "^4.6.3",
"vue": "^3.2.37",
"pascalcase": "^2.0.0",
"prettier": "^2.8.8",
"rimraf": "^5.0.1",
"rollup": "^3.22.0",
"rollup-plugin-typescript2": "^0.34.1",
"semver": "^7.5.1",
"typedoc": "^0.24.8",
"typedoc-plugin-markdown": "^3.15.4",
"typescript": "^5.0.4",
"vitest": "^0.32.4",
"vue": "^3.3.4",
"yorkie": "^2.0.0"
},
"gitHooks": {
"pre-commit": "lint-staged",
"commit-msg": "node scripts/verifyCommit.js"
"commit-msg": "node scripts/verifyCommit.mjs"
},
"lint-staged": {
"*.js": [
Expand All @@ -67,5 +65,8 @@
"*.ts?(x)": [
"prettier --parser=typescript --write"
]
},
"resolutions": {
"@nuxt/kit": "^3.4.3"
}
}
1 change: 1 addition & 0 deletions packages/docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vitepress/cache
Loading

0 comments on commit 98b46fe

Please sign in to comment.