Skip to content
This repository was archived by the owner on May 30, 2025. It is now read-only.

Commit 6799af4

Browse files
committed
added state refs and patching
1 parent 9c3f534 commit 6799af4

File tree

1 file changed

+48
-18
lines changed

1 file changed

+48
-18
lines changed

snippets/pinia.json

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,50 @@
11
{
2-
"Pinia Store": {
3-
"prefix": "pstore",
4-
"body": [
5-
"import { defineStore } from 'pinia'",
6-
"",
7-
"export const useCounterStore = defineStore('counter', {",
8-
"\tstate: () => {",
9-
"\t\treturn { count: 0 }",
10-
"\t},",
11-
"\tactions: {",
12-
"\t\tincrement() {",
13-
"\t\t\tthis.count++",
14-
"\t\t},",
15-
"\t},",
16-
"})"
17-
],
18-
"description": "Basic Pinia Store"
19-
}
2+
"Pinia Store": {
3+
"prefix": "pstore",
4+
"body": [
5+
"import { defineStore } from 'pinia'",
6+
"",
7+
"export const useCounterStore = defineStore('counter', {",
8+
"\tstate: () => {",
9+
"\t\treturn { count: 0 }",
10+
"\t},",
11+
"\tactions: {",
12+
"\t\tincrement() {",
13+
"\t\t\tthis.count++",
14+
"\t\t},",
15+
"\t},",
16+
"})"
17+
],
18+
"description": "Basic Pinia Store"
19+
},
20+
"Pinia Store State Refs": {
21+
"prefix": "pstorestaterefs",
22+
"body": [
23+
"import { useCounterStore } from '@/store/main'",
24+
"",
25+
"const store = useCounterStore()",
26+
"const { count } = storeToRefs(store)",
27+
"// You can access destructured state like so: store.counter++"
28+
],
29+
"description": "Destructure Pinia State"
30+
},
31+
"Pinia Store Patch": {
32+
"prefix": "pstorepatch",
33+
"body": [
34+
"store.$patch({",
35+
"\tcount: store.count++",
36+
"})"
37+
],
38+
"description": "Pinia Store Patch"
39+
},
40+
"Pinia Store Patch Function": {
41+
"prefix": "pstorepatchfunction",
42+
"body": [
43+
"store.$patch((state) => {",
44+
"\tstate.items.push({ name: 'shoes', quantity: 1 })",
45+
"\tstate.hasChanged = true",
46+
"})"
47+
],
48+
"description": "Pinia Store Patch Function"
49+
}
2050
}

0 commit comments

Comments
 (0)