Skip to content

Commit

Permalink
Improvements around types
Browse files Browse the repository at this point in the history
  • Loading branch information
lourot committed Jan 15, 2024
1 parent f33ce0c commit e6826e8
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 13 deletions.
2 changes: 0 additions & 2 deletions packages/vike-pinia/renderer/installPinia.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { createPinia } from 'pinia'
import type { OnCreateAppSync } from 'vike-vue'
import { assert } from '../utils/assert'

export { installPinia }

const installPinia: OnCreateAppSync = (pageContext): ReturnType<OnCreateAppSync> => {
const pinia = createPinia()
assert(pageContext.app)
pageContext.app.use(pinia)
Object.assign(pageContext, { pinia })
}
4 changes: 0 additions & 4 deletions packages/vike-pinia/utils/assert.ts

This file was deleted.

6 changes: 3 additions & 3 deletions vike-vue/renderer/+config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type {
}

import type { Config, ConfigEffect, PageContext } from 'vike/types'
import type { Component } from './types'
import type { Component, PageContextWithApp } from './types'
import type { Plugin } from 'vue'

// Purposeful code duplication for improving QuickInfo IntelliSense
Expand All @@ -21,7 +21,7 @@ import type { Plugin } from 'vue'
* - https://vuejs.org/guide/reusability/plugins.html
* - https://vuejs.org/api/application.html#createapp
*/
type OnCreateAppSync = (pageContext: PageContext) => void
type OnCreateAppSync = (pageContext: PageContextWithApp) => void
/**
* Hook called right after creating Vue's `app` instance.
*
Expand All @@ -31,7 +31,7 @@ type OnCreateAppSync = (pageContext: PageContext) => void
* - https://vuejs.org/guide/reusability/plugins.html
* - https://vuejs.org/api/application.html#createapp
*/
type OnCreateAppAsync = (pageContext: PageContext) => Promise<void>
type OnCreateAppAsync = (pageContext: PageContextWithApp) => Promise<void>

/**
* Hook called right after rendering the page's root Vue component.
Expand Down
5 changes: 1 addition & 4 deletions vike-vue/renderer/app.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { createApp, createSSRApp, defineComponent, h, markRaw, nextTick, reactive } from 'vue'
import type { Component, PageProps, VikeVueApp } from './types'
import type { Component, PageContextWithApp, PageContextWithoutApp, PageProps } from './types'
import type { Config, PageContext } from 'vike/types'
import { setPageContext } from '../components/usePageContext.js'
import { objectAssign } from '../utils/objectAssign'

export { createVueApp }

type PageContextWithoutApp = PageContext & { app: undefined }
type PageContextWithApp = PageContext & { app: VikeVueApp }

/**
* Isomorphic function to create a Vue app.
*
Expand Down
4 changes: 4 additions & 0 deletions vike-vue/renderer/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export type { PageProps }
export type { Component }
export type { PageContextWithApp, PageContextWithoutApp }
export type { VikeVueApp }

import type { PageContext } from 'vike/types'
Expand All @@ -14,6 +15,9 @@ type VikeVueApp = App<Element> & {
changePage: (pageContext: PageContext) => Promise<void>
}

type PageContextWithoutApp = PageContext & { app: undefined }
type PageContextWithApp = PageContext & { app: VikeVueApp }

declare global {
namespace Vike {
interface PageContext {
Expand Down

0 comments on commit e6826e8

Please sign in to comment.