Skip to content

Commit

Permalink
wip: add incomplete missing types
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Jul 8, 2022
1 parent 57e75dc commit fb98904
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/nuxt/src/runtime/plugin.vue2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
16 changes: 16 additions & 0 deletions packages/nuxt/src/runtime/plugin.vue3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
}

0 comments on commit fb98904

Please sign in to comment.