Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Pinia snippets #108

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5b376b0
removed vetur as dep
CRBroughton Nov 18, 2021
00cd321
removed volar section
CRBroughton Nov 18, 2021
289173b
removed yarn.lock
CRBroughton Nov 18, 2021
9384d44
Merge branch 'develop' into main
CRBroughton Nov 18, 2021
9c3f534
added pinia.json
CRBroughton Nov 18, 2021
6799af4
added state refs and patching
CRBroughton Nov 19, 2021
ac7a3e6
updated pinia.json prefixes
CRBroughton Nov 19, 2021
4915240
added pinia table to README.md
CRBroughton Nov 19, 2021
47e4f86
updated keywords
CRBroughton Nov 19, 2021
be6d32e
fixed pstateref description
CRBroughton Nov 19, 2021
c28d07b
pinia state refs prefix changed
CRBroughton Nov 19, 2021
cb34dce
Merge pull request #1 from sdras/main
CRBroughton Feb 20, 2022
61048dc
Merge branch 'main' into develop
CRBroughton Feb 20, 2022
048af80
added store import command
CRBroughton Feb 20, 2022
fcc0ac3
Merge branch 'develop' into main
CRBroughton Feb 20, 2022
4ea1880
Revert "removed yarn.lock"
CRBroughton Feb 20, 2022
ef3aca8
added vue-html
CRBroughton Feb 20, 2022
1d385be
moved composition API scripts to the top
CRBroughton Feb 20, 2022
05d58b2
Merge branch 'script-top-2' into develop
CRBroughton Feb 20, 2022
d28fa47
added defineProps script snippet
CRBroughton Feb 20, 2022
6f7bd69
updated README.md with vdefineprops
CRBroughton Feb 20, 2022
448c097
added vdefineemits
CRBroughton Mar 4, 2022
08dcf84
modified functions to match examples
CRBroughton Mar 7, 2022
02d12e4
changed prefixes
CRBroughton Mar 7, 2022
1d8ac0a
added computed getter setter
CRBroughton Mar 8, 2022
3a7cd0f
added computed get / set to README.md
CRBroughton Mar 8, 2022
5520b75
add v3store command for composition store
CRBroughton May 30, 2022
fc00f32
update defineEmits to 3.3, add defineSlots, add generic component
CRBroughton Jun 11, 2023
c798e05
add spacing to generic component
CRBroughton Jun 11, 2023
f149d00
replace yarn with npm
CRBroughton Jun 11, 2023
4f17a23
Merge branch 'develop'
CRBroughton Jun 11, 2023
b3c56db
add defineModel, update defineEmits & defineSlots
CRBroughton Dec 29, 2023
a7ae345
chore: install changesets, update publisher and vscode engine version…
CRBroughton Nov 22, 2024
cacd116
chore: add .vscodeignore
CRBroughton Nov 22, 2024
c1a704a
chore: update name
CRBroughton Nov 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
tests
*.vsix
bun.lockb
package.json
tsconfig.json
.changeset
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,13 @@ You can enable tab completion (recommended) by opening `Code > Preferences > Set

| Snippet | Purpose |
| ------------------- | ----------------------------------------------------- |
| `v3props` | Vue Composition API - defineProps with Interface |
| `v3emits` | Vue Composition API - defineEmits with Interface |
| `v3store` | Vue Composition API - Store using Provide / Inject |
| `v3reactive` | Vue Composition API - reactive |
| `v3reactive-setup` | Vue Composition API - reactive with setup boilerplate |
| `v3computed` | Vue Composition API - computed |
| `v3computedgetset` | Vue Composition API - computed get / set |
| `v3watch` | Vue Composition API - watcher single source |
| `v3watch-array` | Vue Composition API - watch as array |
| `v3watcheffect` | Vue Composition API - watchEffect |
Expand All @@ -141,6 +145,15 @@ You can enable tab completion (recommended) by opening `Code > Preferences > Set
| `vstore-import` | Import vuex store into main.js |
| `vstore2` | Updated Base for Vuex store |

### Pinia

| Snippet | Purpose |
| --------------- | ------------------------------ |
| `pstore` | Base for Pinia store.ts |
| `pstateref` | Access Pinia State |
| `ppatch` | Pinia Patch |
| `ppatchf` | Pinia Patch Function |

### Vue Router

| Snippet | Purpose |
Expand Down
Binary file added bun.lockb
Binary file not shown.
25 changes: 17 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
{
"name": "vue-vscode-snippets",
"displayName": "Vue VSCode Snippets",
"name": "modern-vue-snippets",
"displayName": "Modern Vue Snippets",
"description": "Snippets that will supercharge your Vue workflow",
"icon": "images/vue-logo.png",
"version": "3.1.1",
"publisher": "sdras",
"version": "3.1.5",
"publisher": "CraigRBroughton",
"engines": {
"vscode": "^1.14.0"
"vscode": "^1.95.3"
},
"repository": {
"type": "git",
"url": "https://github.com/sdras/vue-vscode-snippets.git"
"url": "https://github.com/CRBroughton/vue-vscode-snippets.git"
},
"scripts": {
"build": "vsce package -o vue-vscode-snippets-$npm_package_version.vsix",
"install": "yarn build && code --install-extension vue-vscode-snippets-$npm_package_version.vsix"
"build": "vsce package -o vue-snippets-$npm_package_version.vsix",
"install": "npm run build && code --install-extension vue-snippets-$npm_package_version.vsix",
"changeset": "npx changeset",
"changeset:status": "npx changeset status --verbose",
"changeset:version": "npx changeset version"
},
"keywords": [
"Vue",
"Vue 3",
"Vue 2",
"Composition API",
"Vuex",
"Pinia",
"Vue Snippets"
],
"categories": [
Expand Down Expand Up @@ -79,6 +84,10 @@
{
"language": "typescript",
"path": "./snippets/nuxt-config.json"
},
{
"language": "typescript",
"path": "./snippets/pinia.json"
}
]
}
Expand Down
57 changes: 57 additions & 0 deletions snippets/pinia.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"Pinia Store": {
"prefix": "pstore",
"body": [
"import { defineStore } from 'pinia'",
"",
"export const useCounterStore = defineStore('counter', {",
"\tstate: () => {",
"\t\treturn { count: 0 }",
"\t},",
"\tactions: {",
"\t\tincrement() {",
"\t\t\tthis.count++",
"\t\t},",
"\t},",
"})"
],
"description": "Basic Pinia Store"
},
"Pinia Store State Refs": {
"prefix": "pstateref",
"body": [
"import { useCounterStore } from '@/store/main'",
"",
"const store = useCounterStore()",
"const { count } = storeToRefs(store)",
"// You can access destructured state like so: store.counter++"
],
"description": "Destructure Pinia State"
},
"Pinia Store Patch": {
"prefix": "ppatch",
"body": [
"store.$patch({",
"\tcount: store.count++",
"})"
],
"description": "Pinia Store Patch"
},
"Pinia Store Patch Function": {
"prefix": "ppatchf",
"body": [
"store.$patch((state) => {",
"\tstate.items.push({ name: 'shoes', quantity: 1 })",
"\tstate.hasChanged = true",
"})"
],
"description": "Pinia Store Patch Function"
},
"Pinia Import Store": {
"prefix": "pstore-import",
"body": [
"import { useCounterStore } from '@/store/main'"
],
"description": "Import a Pinia store"
}
}
78 changes: 78 additions & 0 deletions snippets/vue-script.json
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,67 @@
],
"description": "vue.config.js"
},
"Vue Composition API - defineProps with Interface": {
"prefix": "v3props",
"body": [
"interface Props {",
"\t${1:msg: string}",
"}",
"",
"// For default values for your props, use :",
"// withDefaults(defineProps<Props>(), { msg: 'myDefaultValue' })}",
"const props = defineProps<Props>()"
],
"description": "Vue Composition api - defineProps with Interface"
},
"Vue Composition API - defineEmits": {
"prefix": "v3emits",
"body": [
"const emit = defineEmits<{",
"\tfoo: [id: number]",
"\tbar: [name: string, ...rest: any[]]",
"}>()"
],
"description": "Vue Composition api - defineEmits"
},
"Vue Composition API - defineSlots": {
"prefix": "v3slots",
"body": [
"const slots = defineSlots<{",
"\tdefault?: (props: { msg: string }) => any",
"\titem?: (props: { id: number }) => any",
"}>()"
],
"description": "Vue Composition api - defineSlots"
},
"Vue Composition API - defineModel": {
"prefix": "v3model",
"body": [
"const title = defineModel('title', { required: true })"
],
"description": "Vue Composition api - defineModel"
},
"Vue Composition API - Store using Provide / Inject": {
"prefix": "v3store",
"body": [
"import { provide, inject, InjectionKey } from 'vue'",
"",
"const store = () => {}",
"",
"const storeKey: InjectionKey<ReturnType<typeof store>> = Symbol('composition-store')",
"",
"export const provideStore = () => {",
"\tconst state = store()",
"\tprovide(storeKey, state)",
"\treturn state",
"}",
"",
"export const useStore = () => {",
"\treturn inject(storeKey)",
"}"
],
"description": "Vue Composition api - Store using Provide / Inject"
},
"Vue Composition API - Reactive": {
"prefix": "v3reactive",
"body": ["const ${1:name} = reactive({", "\t${2:count}: ${3:0}", "})"],
Expand All @@ -314,6 +375,23 @@
"body": ["const ${1:name} = computed(() => {", "\treturn ${2}", "})"],
"description": "Vue Composition api - computed"
},
"Vue Composition API - Computed Get / Set": {
"prefix": "v3computedgetset",
"body": [
"const props = defineProps(['modelValue'])",
"const emit = defineEmits(['update:modelValue'])",
"",
"const value = computed({",
"\tget() {",
"\t\treturn props.modelValue",
"\t},",
"\tset(value: string) {",
"\t\temit('update:modelValue', value)",
"\t}",
"})"
],
"description": "Vue Composition api - computed get / set"
},
"Vue Composition API - watch - single source": {
"prefix": "v3watch",
"body": ["watch(() => ${1:foo}, (newValue, oldValue) => {", "\t${2}", "})"],
Expand Down
78 changes: 50 additions & 28 deletions snippets/vue.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,6 @@
"Vue Single File Component Composition API": {
"prefix": "vbase-3",
"body": [
"<template>",
"\t<div>",
"",
"\t</div>",
"</template>",
"",
"<script>",
"export default {",
"\tsetup () {",
Expand All @@ -184,7 +178,13 @@
"}",
"</script>",
"",
"<style lang=\"scss\" scoped>",
"<template>",
"\t<div>",
"",
"\t</div>",
"</template>",
"",
"<style scoped lang=\"scss\">",
"",
"</style>"
],
Expand All @@ -193,17 +193,17 @@
"Vue Single File Component Setup Composition API": {
"prefix": "vbase-3-setup",
"body": [
"<script setup>",
"",
"</script>",
"",
"<template>",
"\t<div>",
"",
"\t</div>",
"</template>",
"",
"<script setup>",
"",
"</script>",
"",
"<style lang=\"scss\" scoped>",
"<style scoped lang=\"scss\">",
"",
"</style>"
],
Expand All @@ -212,12 +212,6 @@
"Vue Single File Component Composition API Reactive": {
"prefix": "vbase-3-reactive",
"body": [
"<template>",
"\t<div>",
"",
"\t</div>",
"</template>",
"",
"<script>",
"import { reactive, toRefs } from 'vue'",
"",
Expand All @@ -234,7 +228,13 @@
"}",
"</script>",
"",
"<style lang=\"scss\" scoped>",
"<template>",
"\t<div>",
"",
"\t</div>",
"</template>",
"",
"<style scoped lang=\"scss\">",
"",
"</style>"
],
Expand All @@ -243,12 +243,6 @@
"Vue Single File Component Composition API with Typescript": {
"prefix": "vbase-3-ts",
"body": [
"<template>",
"\t<div>",
"",
"\t</div>",
"</template>",
"",
"<script lang=\"ts\">",
"import { defineComponent } from 'vue'",
"",
Expand All @@ -260,6 +254,12 @@
"})",
"</script>",
"",
"<template>",
"\t<div>",
"",
"\t</div>",
"</template>",
"",
"<style scoped>",
"",
"</style>"
Expand All @@ -269,21 +269,43 @@
"Vue Single File Component Setup Composition API with Typescript": {
"prefix": "vbase-3-ts-setup",
"body": [
"<script setup lang=\"ts\">",
"",
"</script>",
"",
"<template>",
"\t<div>",
"",
"\t</div>",
"</template>",
"",
"<script setup lang=\"ts\">",
"<style scoped>",
"",
"</style>"
],
"description": "Base for Vue File Setup Composition API - Typescript"
},
"Vue Single File Generic Component": {
"prefix": "vbase-3-generic",
"body": [
"<script setup lang=\"ts\" generic=\"T\">",
"const props = defineProps<{",
"items: T[]",
"selected: T",
"}>()",
"",
"</script>",
"",
"<template>",
"\t<div>",
"",
"\t</div>",
"</template>",
"",
"<style scoped>",
"",
"</style>"
],
"description": "Base for Vue File Setup Composition API - Typescript"
]
},
"Vue Single File Component with Class based Typescript format": {
"prefix": "vbase-ts-class",
Expand Down
4 changes: 0 additions & 4 deletions yarn.lock

This file was deleted.