]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
wip: add incomplete missing types
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 8 Jul 2022 15:12:26 +0000 (17:12 +0200)
committerEduardo San Martin Morote <posva@users.noreply.github.com>
Wed, 13 Jul 2022 10:32:58 +0000 (12:32 +0200)
packages/nuxt/src/runtime/plugin.vue2.ts
packages/nuxt/src/runtime/plugin.vue3.ts

index 085ee9c02f789937fc500f09268f0b7ac14f9e14..c7f848e07111e62d5327b36975d1e3e5357cdede 100644 (file)
@@ -10,6 +10,13 @@ export default (context: any, inject: any) => {
   context.app.pinia = pinia
   setActivePinia(pinia)
 
+  // add access to `$nuxt`
+  // @ts-expect-error: _p is internal
+  pinia._p.push(({ store }) => {
+    // make it non enumerable so it avoids any serialization and devtools
+    Object.defineProperty(store, '$nuxt', { value: context })
+  })
+
   if (process.server) {
     context.beforeNuxtRender((ctx: any) => {
       ctx.nuxtState.pinia = pinia.state.value
@@ -21,3 +28,13 @@ export default (context: any, inject: any) => {
   // Inject $pinia
   inject('pinia', pinia)
 }
+
+declare module 'pinia' {
+  export interface PiniaCustomProperties {
+    /**
+     * Nuxt context.
+     */
+    // FIXME: where is this type?
+    // $nuxt: import('@nuxt/types').Context
+  }
+}
index 11d8eb21acb63906414a14df751e19e200f15c87..608df03c7fbe00c13a013b6f484cc9d21dcb29bd 100644 (file)
@@ -6,6 +6,12 @@ export default defineNuxtPlugin((nuxtApp) => {
   nuxtApp.vueApp.use(pinia)
   setActivePinia(pinia)
 
+  // @ts-expect-error: _p is internal
+  pinia._p.push(({ store }) => {
+    // make it non enumerable so it avoids any serialization and devtools
+    Object.defineProperty(store, '$nuxt', { value: nuxtApp })
+  })
+
   if (process.server) {
     nuxtApp.payload.pinia = pinia.state.value
   } else if (nuxtApp.payload && nuxtApp.payload.pinia) {
@@ -19,3 +25,13 @@ export default defineNuxtPlugin((nuxtApp) => {
     },
   }
 })
+
+declare module 'pinia' {
+  export interface PiniaCustomProperties {
+    /**
+     * Nuxt context.
+     */
+    // FIXME: where is this type?
+    // $nuxt: import('@nuxt/types').Context
+  }
+}