Skip to content

Commit

Permalink
rename hydrate / dehydrate hooks
Browse files Browse the repository at this point in the history
Signed-off-by: Chris-Robin Ennen <[email protected]>
  • Loading branch information
4350pChris authored and lourot committed Jan 15, 2024
1 parent 9104ecf commit dd9274d
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/vike-pinia/renderer/+config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import type { Pinia } from 'pinia'

export default {
onCreateApp: 'import:vike-pinia/renderer/installPinia:installPinia',
dehydrateStore: 'import:vike-pinia/renderer/dehydratePinia:dehydratePinia',
hydrateStore: 'import:vike-pinia/renderer/hydratePinia:hydratePinia',
onAfterRenderSSRApp: 'import:vike-pinia/renderer/dehydratePinia:dehydratePinia',
onBeforeMountApp: 'import:vike-pinia/renderer/hydratePinia:hydratePinia',
}

declare global {
Expand Down
4 changes: 2 additions & 2 deletions packages/vike-pinia/renderer/dehydratePinia.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { DehydrateStore } from 'vike-vue';
import type { OnAfterRenderSSRApp } from 'vike-vue';

export { dehydratePinia }

const dehydratePinia: DehydrateStore = ({ pinia }): ReturnType<DehydrateStore> => {
const dehydratePinia: OnAfterRenderSSRApp = ({ pinia }): ReturnType<OnAfterRenderSSRApp> => {
if (!pinia) {
console.warn("[vike-pinia] Missing pinia from pageContext. Did you forget to use `installPinia()` in `+onCreateApp()`?")
return
Expand Down
4 changes: 2 additions & 2 deletions packages/vike-pinia/renderer/hydratePinia.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { HydrateStore } from 'vike-vue'
import type { OnBeforeMountApp } from 'vike-vue'

export { hydratePinia }

const hydratePinia: HydrateStore = ({ pinia, initialStoreState }): ReturnType<HydrateStore> => {
const hydratePinia: OnBeforeMountApp = ({ pinia, initialStoreState }): ReturnType<OnBeforeMountApp> => {
if (!pinia) {
console.warn("[vike-pinia] Missing pinia from pageContext. Did you forget to use `installPinia()` in `+onCreateApp()`?")
return
Expand Down
14 changes: 7 additions & 7 deletions vike-vue/renderer/+config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type { OnCreateAppSync }
export type { OnCreateAppAsync }
export type { DehydrateStore, HydrateStore }
export type { OnAfterRenderSSRApp, OnBeforeMountApp }

import type { Config, ConfigEffect, PageContext } from 'vike/types'
import type { Component, PageContextWithApp } from './types'
Expand Down Expand Up @@ -28,9 +28,9 @@ type OnCreateAppSync = (pageContext: PageContextWithApp) => void
*/
type OnCreateAppAsync = (pageContext: PageContextWithApp) => Promise<void>

type DehydrateStore = (pageContext: PageContextWithApp) => any
type OnAfterRenderSSRApp = (pageContext: PageContextWithApp) => any

type HydrateStore = (pageContext: PageContextWithApp) => void
type OnBeforeMountApp = (pageContext: PageContextWithApp) => void

// Depending on the value of `config.meta.ssr`, set other config options' `env`
// accordingly.
Expand Down Expand Up @@ -106,10 +106,10 @@ export default {
onCreateApp: {
env: { server: true, client: true }
},
dehydrateStore: {
onAfterRenderSSRApp: {
env: { server: true }
},
hydrateStore: {
onBeforeMountApp: {
env: { server: false, client: true }
},
}
Expand Down Expand Up @@ -182,9 +182,9 @@ declare global {
*/
onCreateApp?: OnCreateAppSync | OnCreateAppAsync

dehydrateStore?: DehydrateStore
onAfterRenderSSRApp?: OnAfterRenderSSRApp

hydrateStore?: HydrateStore
onBeforeMountApp?: OnBeforeMountApp
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion vike-vue/renderer/onRenderClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const onRenderClient: OnRenderClientAsync = async (pageContext): ReturnType<OnRe
const ctxWithApp = createVueApp(pageContext, ssr)
app = ctxWithApp.app

pageContext.config.hydrateStore?.(ctxWithApp)
pageContext.config.onBeforeMountApp?.(ctxWithApp)

app.mount(container)
} else {
Expand Down
2 changes: 1 addition & 1 deletion vike-vue/renderer/onRenderHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const onRenderHtml: OnRenderHtmlAsync = async (pageContext): ReturnType<OnRender
? dangerouslySkipEscape(await renderToStringWithErrorHandling(app))
: renderToNodeStreamWithErrorHandling(app)

storeState = pageContext.config.dehydrateStore?.(ctxWithApp)
storeState = pageContext.config.onAfterRenderSSRApp?.(ctxWithApp)
}

const title = getTitle(pageContext)
Expand Down

0 comments on commit dd9274d

Please sign in to comment.